Skip to content

Commit

Permalink
Merge pull request #4248 from nunit/port-pr-4151
Browse files Browse the repository at this point in the history
Port benchmark project to main
  • Loading branch information
rprouse committed Feb 21, 2023
2 parents dc05058 + 7b9ba2a commit 8bd25e6
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,4 @@ project.lock.json
*.out
.ionide
.fake
BenchmarkDotNet.Artifacts*
6 changes: 6 additions & 0 deletions nunit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nunitlite", "nunitlite", "{
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "nunit.testdata.fsharp", "src\NUnitFramework\testdata.fsharp\nunit.testdata.fsharp.fsproj", "{9DF6B262-70E2-44E3-A436-3B65C7FD88DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nunit.framework.benchmarks", "src\NUnitFramework\benchmarks\nunit.framework.benchmarks\nunit.framework.benchmarks.csproj", "{D0D08E09-8FF4-487D-AE61-C9CCCCA8CBB0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -95,6 +97,10 @@ Global
{9DF6B262-70E2-44E3-A436-3B65C7FD88DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9DF6B262-70E2-44E3-A436-3B65C7FD88DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9DF6B262-70E2-44E3-A436-3B65C7FD88DE}.Release|Any CPU.Build.0 = Release|Any CPU
{D0D08E09-8FF4-487D-AE61-C9CCCCA8CBB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D0D08E09-8FF4-487D-AE61-C9CCCCA8CBB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0D08E09-8FF4-487D-AE61-C9CCCCA8CBB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0D08E09-8FF4-487D-AE61-C9CCCCA8CBB0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
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);
}
}
}
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));
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>
8 changes: 8 additions & 0 deletions src/NUnitFramework/framework/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
"bee5e972a004ddd692dec8fa404ba4591e847a8cf35de21c2d3" +
"723bc8d775a66b594adeb967537729fe2a446b548cd57a6")]

[assembly: InternalsVisibleTo("nunit.framework.benchmarks, PublicKey=002400000480000094" +
"000000060200000024000052534131000400000100010031eea" +
"370b1984bfa6d1ea760e1ca6065cee41a1a279ca234933fe977" +
"a096222c0e14f9e5a17d5689305c6d7f1206a85a53c48ca0100" +
"80799d6eeef61c98abd18767827dc05daea6b6fbd2e868410d9" +
"bee5e972a004ddd692dec8fa404ba4591e847a8cf35de21c2d3" +
"723bc8d775a66b594adeb967537729fe2a446b548cd57a6")]

#if NET462
[assembly: AssemblyTitle("NUnit Framework (.NET Framework 4.6.2)")]
#elif NETSTANDARD2_0
Expand Down

0 comments on commit 8bd25e6

Please sign in to comment.