Skip to content

Commit

Permalink
floating benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLloyd committed Nov 26, 2023
1 parent ce7a471 commit 8c327bd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Tests/BenchmarkTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace Tests;

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Running;
using Xunit;

public class BenchmarkTests(Xunit.Abstractions.ITestOutputHelper output)
{
[Fact]
public void BenchmarkDotNet_Perf()
{
var logger = new AccumulationLogger();
BenchmarkRunner.Run<FloatingBenchmarks>(DefaultConfig.Instance.AddLogger(logger));
output.WriteLine(logger.GetLog());
}
}

public class FloatingBenchmarks
{
decimal m1;
double d1;
decimal m2;
double d2;

[GlobalSetup]
public void Setup()
{
d1 = 12345.6789;
d2 = 1234.56778;
m1 = 12345.6789M;
m2 = 1234.56778M;
}

[Benchmark(Baseline = true)]
public double DoubleAdd() => d1 + d2;

[Benchmark]
public decimal DecimalAdd() => m1 + m2;
}
1 change: 1 addition & 0 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" PrivateAssets="All" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.10" />
<PackageReference Include="Meziantou.Xunit.ParallelTestFramework" Version="2.1.0" />
<PackageReference Include="Rationals" Version="2.3.0" />
<ProjectReference Include="..\CsCheck\CsCheck.csproj" />
Expand Down

0 comments on commit 8c327bd

Please sign in to comment.