From 8c327bdf4d4a7b14f2a70b8fc8ddd44a84ae322b Mon Sep 17 00:00:00 2001 From: Anthony Lloyd Date: Sun, 26 Nov 2023 11:31:23 +0000 Subject: [PATCH] floating benchmark --- Tests/BenchmarkTests.cs | 41 +++++++++++++++++++++++++++++++++++++++++ Tests/Tests.csproj | 1 + 2 files changed, 42 insertions(+) create mode 100644 Tests/BenchmarkTests.cs diff --git a/Tests/BenchmarkTests.cs b/Tests/BenchmarkTests.cs new file mode 100644 index 0000000..f3fd816 --- /dev/null +++ b/Tests/BenchmarkTests.cs @@ -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(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; +} \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index a063cb2..e6e4db0 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -16,6 +16,7 @@ +