diff --git a/source/Quantities.Benchmark/Compare/Creation.cs b/source/Quantities.Benchmark/Compare/Creation.cs new file mode 100644 index 00000000..f902c9ce --- /dev/null +++ b/source/Quantities.Benchmark/Compare/Creation.cs @@ -0,0 +1,33 @@ +using BenchmarkDotNet.Attributes; +using Quantities.Prefixes; +using Quantities.Units.Si; + +namespace Quantities.Benchmark.Compare; + +[MemoryDiagnoser] +public class Creation +{ + private static Double value = Math.E; + + [Benchmark(Baseline = true)] + public UnitsNet.Length CreateUnitsNet() => UnitsNet.Length.FromCentimeters(value); + + [Benchmark] + public Length CreateQuantity() => Length.Of(value).Si(); +} + +/* +// * Summary * + +BenchmarkDotNet v0.13.8, Arch Linux +Intel Core i7-8565U CPU 1.80GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores +.NET SDK 7.0.111 + [Host] : .NET 7.0.11 (7.0.1123.46301), X64 RyuJIT AVX2 + DefaultJob : .NET 7.0.11 (7.0.1123.46301), X64 RyuJIT AVX2 + + +| Method | Mean | Error | StdDev | Ratio | Allocated | Alloc Ratio | +|--------------- |---------:|---------:|---------:|------:|----------:|------------:| +| CreateUnitsNet | 13.02 ns | 0.129 ns | 0.114 ns | 1.00 | - | NA | +| CreateQuantity | 10.70 ns | 0.046 ns | 0.038 ns | 0.82 | - | NA | +*/ diff --git a/source/Quantities.Benchmark/Compare/Multiplication.cs b/source/Quantities.Benchmark/Compare/Multiplication.cs new file mode 100644 index 00000000..57bff4f9 --- /dev/null +++ b/source/Quantities.Benchmark/Compare/Multiplication.cs @@ -0,0 +1,39 @@ +using BenchmarkDotNet.Attributes; +using Quantities.Prefixes; +using Quantities.Units.Imperial.Length; +using Quantities.Units.Si; + +using nLength = UnitsNet.Length; + +namespace Quantities.Benchmark.Compare; + +[MemoryDiagnoser] +public class Multiplication +{ + private static readonly Length left = Length.Of(3).Si(); + private static readonly Length right = Length.Of(4).Imperial(); + private static readonly nLength nLeft = nLength.FromMillimeters(3); + private static readonly nLength nRight = nLength.FromMillimeters(4); + + [Benchmark(Baseline = true)] + public UnitsNet.Area UnitsNetMultiply() => nLeft * nRight; + + [Benchmark] + public Area QuantityMultiply() => left * right; +} + +/* +// * Summary * + +BenchmarkDotNet v0.13.8, Arch Linux +Intel Core i7-8565U CPU 1.80GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores +.NET SDK 7.0.111 + [Host] : .NET 7.0.11 (7.0.1123.46301), X64 RyuJIT AVX2 + DefaultJob : .NET 7.0.11 (7.0.1123.46301), X64 RyuJIT AVX2 + + +| Method | Mean | Error | StdDev | Ratio | Allocated | Alloc Ratio | +|----------------- |---------:|---------:|---------:|------:|----------:|------------:| +| UnitsNetMultiply | 78.01 ns | 0.527 ns | 0.493 ns | 1.00 | - | NA | +| QuantityMultiply | 10.64 ns | 0.046 ns | 0.041 ns | 0.14 | - | NA | +*/ diff --git a/source/Quantities.Benchmark/Quantities.Benchmark.csproj b/source/Quantities.Benchmark/Quantities.Benchmark.csproj index 10c091ca..fa874fd9 100644 --- a/source/Quantities.Benchmark/Quantities.Benchmark.csproj +++ b/source/Quantities.Benchmark/Quantities.Benchmark.csproj @@ -18,6 +18,7 @@ +