-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add a BenchmarkDotNet project #52123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -140,7 +140,8 @@ | |||||
| <MoqPackageVersion>4.18.4</MoqPackageVersion> | ||||||
| <XunitCombinatorialVersion>1.3.2</XunitCombinatorialVersion> | ||||||
| <MicrosoftDotNetInstallerWindowsSecurityTestDataPackageVersion>8.0.0-beta.23607.1</MicrosoftDotNetInstallerWindowsSecurityTestDataPackageVersion> | ||||||
| <BenchmarkDotNetPackageVersion>0.14.0</BenchmarkDotNetPackageVersion> | ||||||
| <BenchmarkDotNetPackageVersion>0.15.6</BenchmarkDotNetPackageVersion> | ||||||
| <BenchmarkDotNetDiagnosticsWindowsPackageVersion>0.14.0</BenchmarkDotNetDiagnosticsWindowsPackageVersion> | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
If these packages version together we may want to use a single property to ensure they don't drift. |
||||||
| </PropertyGroup> | ||||||
| <PropertyGroup Label="Workload manifest package versions"> | ||||||
| <MauiFeatureBand>10.0.100</MauiFeatureBand> | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>$(ToolsetTargetFramework)</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
|
|
||
| <ExcludeFromSourceOnlyBuild>true</ExcludeFromSourceOnlyBuild> | ||
| <CanRunTestAsTool>false</CanRunTestAsTool> | ||
| <IsTestProject>false</IsTestProject> | ||
| <IsUnitTestProject>false</IsUnitTestProject> | ||
| <IncludeTestUsings>false</IncludeTestUsings> | ||
| <NoWarn>$(NoWarn);CS8002</NoWarn> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="BenchmarkDotNet" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\src\Cli\dotnet\dotnet.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <!-- Copy to output so BenchmarkDotNet generated projects inherit this as well --> | ||
| <None Include="Directory.Build.props" CopyToOutputDirectory="PreserveNewest" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project> | ||
| <PropertyGroup> | ||
| <!-- | ||
| We need to output to something other than the normal bin and obj folders to prevent picking up the global.json that | ||
| is being dropped there as that will break building the project that BenchmarkDotNet generates to run the benchmarks. | ||
| --> | ||
| <BaseOutputPath>$([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)', '..', '..', 'artifacts', '$(MSBuildProjectName)', 'bin'))</BaseOutputPath> | ||
| <BaseIntermediateOutputPath>$([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)', '..', '..', 'artifacts', '$(MSBuildProjectName)', 'obj'))</BaseIntermediateOutputPath> | ||
|
Comment on lines
+7
to
+8
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's an ambient property called |
||
|
|
||
| <!-- | ||
| Skipping here as we want the auto-generated projects to skip as well. The project file will copy this Directory.Build.props | ||
| to the output folder and the auto-generated projects will implicitly import it. | ||
| --> | ||
| <SkipCustomizeXlfSourceNames>true</SkipCustomizeXlfSourceNames> | ||
| </PropertyGroup> | ||
| <Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..'))"/> | ||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using BenchmarkDotNet.Attributes; | ||
|
|
||
| namespace Benchmark; | ||
|
|
||
| [MemoryDiagnoser] | ||
| [SimpleJob(launchCount: 1, warmupCount: 1, iterationCount: 1, invocationCount: 1)] | ||
| public class InfoTests | ||
| { | ||
| private static readonly string[] s_args = ["--info"]; | ||
|
|
||
| [Benchmark] | ||
| public int RunInfoCommand() | ||
| { | ||
| return Microsoft.DotNet.Cli.Program.Main(s_args); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using BenchmarkDotNet.Running; | ||
|
|
||
| namespace Benchmark; | ||
|
|
||
| internal class Program | ||
| { | ||
| static void Main(string[] args) | ||
| { | ||
| BenchmarkRunner.Run(typeof(Program).Assembly); | ||
|
|
||
| // BenchmarkDotNet bakes a fair amount of assumptions into the way it generates | ||
| // projects for running its benchmarks. One of the key problems we run into is how | ||
| // it figures out the root of the repository. It walks up the directory structure | ||
| // to find the first folder with a `*.sln` or `*.slnx` or `global.json`. It then | ||
| // searches down from there to find the project file. In the SDK repo currently | ||
| // we have a `global.json` in the `artifacts/bin` folder- that prevents it from | ||
| // finding the project file. | ||
| // | ||
| // We work around this currently by redirecting the output to `artifacts/Benchmark`. | ||
| // One partially explored alternative was to derive the `CsProjGenerator` and customize | ||
| // its `GetProjectFilePath(Type benchmarkTarget, ILogger logger)`. There is a fair | ||
| // amount of logic there that needs reimplemented, and you have to create a custom | ||
| // toolchain something like this: | ||
| // | ||
| // public class CustomToolchain : Toolchain | ||
| // { | ||
| // public CustomToolchain(string? tfm = default) : base( | ||
| // "CustomToolchain", | ||
| // new CustomCsProjGenerator( | ||
| // targetFrameworkMoniker: tfm ?? GetCurrentTfm(), | ||
| // cliPath: null, | ||
| // packagesPath: null, | ||
| // runtimeFrameworkVersion: null), | ||
| // new DotNetCliBuilder(tfm ?? GetCurrentTfm()), | ||
| // new DotNetCliExecutor(customDotNetCliPath: null)) { } | ||
| // } | ||
| // | ||
| // Things still break with the `bin/global.json` with this. Pulling in and tweaking | ||
| // everything that is needed to get the temporary project to build successfully looks | ||
| // to be a potential whack-a-mole problem, so starting by rooting the output in a new | ||
| // folder in the `artifacts` directory that ensures the repo root's `global.json` is | ||
| // in "scope" so we don't have to modify the toolchain. | ||
| // | ||
| // https://github.com/dotnet/BenchmarkDotNet/blob/master/src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ | |
|
|
||
| <!-- Global usings --> | ||
| <!-- See: https://learn.microsoft.com/dotnet/core/project-sdk/msbuild-props#using --> | ||
| <ItemGroup> | ||
| <ItemGroup Condition="'$(IncludeTestUsings)'!='false'"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's worth having a top-level |
||
| <Using Include="FluentAssertions" /> | ||
| <Using Include="Microsoft.NET.TestFramework" /> | ||
| <Using Include="Microsoft.NET.TestFramework.Assertions" /> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need both this Condition and the change to the DependsOnTargets - if a Condition evaluates to
falsethen the DependsOnTargets should not be run at all. Were you seeing different?