Skip to content

Conversation

@timcassell
Copy link
Collaborator

@timcassell timcassell commented Jun 21, 2023

Fixes #1133
Fixes #2305
Fixes #1802
Fixes #2530

  • Drastically simplified benchmark type code gen.
  • Overhead return type is always void for a fair baseline for all benchmark return types.
  • Benchmark method is called directly instead of wrapped in a delegate.
  • Return value is popped off the stack instead of passed to Consumer or a NoInlining method.
  • Added an assembly weaver that automatically applies MethodImplOptions.NoInlining to benchmark methods.
  • Added additional tests.

@timcassell

This comment was marked as outdated.

@timcassell timcassell force-pushed the fair-types branch 2 times, most recently from 48266cd to 4abbb1f Compare March 11, 2024 14:08
@timcassell timcassell modified the milestones: v0.14.0, v0.15.x Aug 6, 2024
@timcassell timcassell marked this pull request as draft January 13, 2025 00:58
@timcassell timcassell mentioned this pull request Feb 13, 2025
@timcassell timcassell changed the title Fair Return Types Improve Benchmark Accuracy Feb 13, 2025
@timcassell timcassell marked this pull request as ready for review February 13, 2025 21:53
@timcassell
Copy link
Collaborator Author

timcassell commented Feb 13, 2025

Unfortunately, I no longer have an Intel CPU to test this, but I think the new results from this PR should address the issues you had in #2334 @AndreyAkinshin (results look good on my AMD 9800X3D CPU in .Net 8).

Don't fail silently.
Remove unused property.
Embed the weaver into BenchmarkDotNet.Annotations package instead of another package dependency.
@AndyAyersMS
Copy link
Member

@dotnet/jit-contrib any thoughts on this?

Fixed formatting.
# Conflicts:
#	BenchmarkDotNet.sln
#	NuGet.Config
#	build/common.props
#	src/BenchmarkDotNet.Annotations/BenchmarkDotNet.Annotations.csproj
#	src/BenchmarkDotNet/Code/CodeGenerator.cs
#	src/BenchmarkDotNet/Templates/BenchmarkType.txt
#	src/BenchmarkDotNet/Toolchains/InProcess/Emit/Implementation/Emitters/RunnableEmitter.cs
#	tests/BenchmarkDotNet.Tests/Running/RunningEmptyBenchmarkTests.cs
@timcassell
Copy link
Collaborator Author

Interestingly, on Apple M3, an empty method is measured at 0.9ns while a method that increments a field is measured at 0.66ns, which results in the overhead measurement looking "wrong". I don't know if this is specific to M chips or Arm in general, but it doesn't happen on xArch. There does not seem to be a good way for BDN to account for this μarch quirk.

@timcassell timcassell merged commit c1359cb into dotnet:master Dec 7, 2025
15 of 16 checks passed
@timcassell timcassell deleted the fair-types branch December 7, 2025 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

4 participants