-
Notifications
You must be signed in to change notification settings - Fork 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4248 from nunit/port-pr-4151
Port benchmark project to main
- Loading branch information
Showing
6 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,3 +189,4 @@ project.lock.json | |
*.out | ||
.ionide | ||
.fake | ||
BenchmarkDotNet.Artifacts* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/NUnitFramework/benchmarks/nunit.framework.benchmarks/FrameworkControllerBenchmark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// *********************************************************************** | ||
// Copyright (c) 2022 Charlie Poole | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// *********************************************************************** | ||
|
||
using System.Collections; | ||
using BenchmarkDotNet.Attributes; | ||
using NUnit.Framework.Api; | ||
using NUnit.Framework.Interfaces; | ||
using NUnit.Framework.Internal; | ||
using NUnit.Framework.Internal.Execution; | ||
using NUnit.Framework.Internal.Filters; | ||
|
||
namespace NUnit.Framework; | ||
|
||
[InProcess] // need to use so that we get correct test loading | ||
[MemoryDiagnoser] | ||
public class FrameworkControllerBenchmark | ||
{ | ||
private FrameworkController _controller; | ||
private List<string> _testIds; | ||
private string _orFilter; | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
var settings = new Hashtable | ||
{ | ||
{ "ProcessModel", "InProcess" }, | ||
{ "DomainUsage", "None" }, | ||
{ "ShadowCopyFiles", false }, | ||
{ "TestParametersDictionary", "" }, | ||
{ "NumberOfTestWorkers", 0 }, | ||
{ "SynchronousEvents", "false" }, | ||
{ "RandomSeed", 878248866 }, | ||
{ "LOAD", new List<string> { "NUnit.Framework" } }, | ||
{ "WorkDirectory", Path.GetTempPath() }, | ||
}; | ||
_controller = new FrameworkController(typeof(WorkItemTests).Assembly, "0-", settings); | ||
_controller.LoadTests(); | ||
|
||
_testIds = new List<string>(); | ||
var exploreTests = _controller.Runner.ExploreTests(TestFilter.Empty); | ||
GatherTestIds(exploreTests.Tests, _testIds); | ||
|
||
_orFilter = "<filter>" + new OrFilter(_testIds.Select(x => (TestFilter)new IdFilter(x)).ToArray()).ToXml(true).OuterXml + "</filter>"; | ||
} | ||
|
||
[Benchmark] | ||
public int CountTestsEmptyFilter() | ||
{ | ||
var count = _controller.CountTests("<filter/>"); | ||
return count; | ||
} | ||
|
||
[Benchmark] | ||
public int CountTestsWithCategoryFilter() | ||
{ | ||
var count = _controller.CountTests("<filter><cat>Dummy</cat></filter>"); | ||
return count; | ||
} | ||
|
||
[Benchmark] | ||
public int CountTestsWithOrFilterAll() | ||
{ | ||
var count = _controller.CountTests(_orFilter); | ||
return count; | ||
} | ||
|
||
[Benchmark] | ||
public string LoadTests() | ||
{ | ||
return _controller.LoadTests(); | ||
} | ||
|
||
private static void GatherTestIds(IList<ITest> tests, List<string> collector) | ||
{ | ||
foreach (var child in tests) | ||
{ | ||
collector.Add(child.Id); | ||
GatherTestIds(child.Tests, collector); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/NUnitFramework/benchmarks/nunit.framework.benchmarks/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// *********************************************************************** | ||
// Copyright (c) 2022 Charlie Poole | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// *********************************************************************** | ||
|
||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Running; | ||
using NUnit.Framework; | ||
|
||
BenchmarkSwitcher.FromAssembly(typeof(FrameworkControllerBenchmark).Assembly).Run(args, | ||
ManualConfig | ||
.Create(DefaultConfig.Instance) | ||
// while optimize is false for main framework output | ||
.WithOptions(ConfigOptions.DisableOptimizationsValidator)); |
22 changes: 22 additions & 0 deletions
22
src/NUnitFramework/benchmarks/nunit.framework.benchmarks/nunit.framework.benchmarks.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<LangVersion>latest</LangVersion> | ||
<Optimize>true</Optimize> | ||
<AssemblyOriginatorKeyFile>..\..\..\nunit.snk</AssemblyOriginatorKeyFile> | ||
<RootNamespace>NUnit.Framework</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\framework\nunit.framework.csproj" /> | ||
<ProjectReference Include="..\..\tests\nunit.framework.tests.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters