Skip to content

Commit

Permalink
Update the performance comparisons.
Browse files Browse the repository at this point in the history
  • Loading branch information
atmoos committed Nov 25, 2023
1 parent 6fc3a3d commit b95d012
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 39 deletions.
23 changes: 11 additions & 12 deletions source/Quantities.Benchmark/Compare/ComplexCreation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using BenchmarkDotNet.Attributes;
using Quantities.Prefixes;
using Quantities.Units.Si;
using Quantities.Units.Si.Metric;
Expand All @@ -11,13 +10,13 @@ public class ComplexCreation
private static readonly Double value = Math.E;

[Benchmark(Baseline = true)]
public Volume CreateQuantity() => Volume.Of(value).Cubic.Si<Centi, Metre>();
public Volume CreateQuantity() => Volume.Of(value, Cubic(Si<Centi, Metre>()));

[Benchmark]
public UnitsNet.Volume CreateUnitsNet() => UnitsNet.Volume.FromCubicCentimeters(value);

[Benchmark]
public Volume CreateQuantityCentiLitre() => Volume.Of(value).Metric<Centi, Litre>();
public Volume CreateQuantityCentiLitre() => Volume.Of(value, Metric<Centi, Litre>());

[Benchmark]
public UnitsNet.Volume CreateUnitsNetCentiLitre() => UnitsNet.Volume.FromCentiliters(value);
Expand All @@ -27,15 +26,15 @@ public class ComplexCreation
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
.NET SDK 7.0.113
[Host] : .NET 7.0.13 (7.0.1323.52501), X64 RyuJIT AVX2
DefaultJob : .NET 7.0.13 (7.0.1323.52501), X64 RyuJIT AVX2
| Method | Mean | Error | StdDev | Ratio | Allocated | Alloc Ratio |
|------------------------- |---------:|---------:|---------:|------:|----------:|------------:|
| CreateQuantity | 23.63 ns | 0.247 ns | 0.231 ns | 1.00 | - | NA |
| CreateUnitsNet | 12.92 ns | 0.044 ns | 0.041 ns | 0.55 | - | NA |
| CreateQuantityCentiLitre | 27.19 ns | 0.068 ns | 0.064 ns | 1.15 | - | NA |
| CreateUnitsNetCentiLitre | 12.66 ns | 0.095 ns | 0.089 ns | 0.54 | - | NA |
| Method | Mean | Error | StdDev | Ratio | RatioSD | Allocated | Alloc Ratio |
|------------------------- |----------:|----------:|----------:|------:|--------:|----------:|------------:|
| CreateQuantity | 5.076 ns | 0.0454 ns | 0.0425 ns | 1.00 | 0.00 | - | NA |
| CreateUnitsNet | 13.141 ns | 0.0400 ns | 0.0355 ns | 2.59 | 0.02 | - | NA |
| CreateQuantityCentiLitre | 13.738 ns | 0.0480 ns | 0.0449 ns | 2.71 | 0.03 | - | NA |
| CreateUnitsNetCentiLitre | 12.870 ns | 0.0431 ns | 0.0403 ns | 2.54 | 0.02 | - | NA |
*/
16 changes: 7 additions & 9 deletions source/Quantities.Benchmark/Compare/Division.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using BenchmarkDotNet.Attributes;
using Quantities.Prefixes;
using Quantities.Units.Imperial.Length;
using Quantities.Units.Si;
using Quantities.Units.Si.Metric;
using nLength = UnitsNet.Length;
using nVolume = UnitsNet.Volume;
Expand All @@ -11,8 +9,8 @@ namespace Quantities.Benchmark.Compare;
[MemoryDiagnoser]
public class Division
{
private static readonly Volume left = Volume.Of(32).Metric<Centi, Litre>();
private static readonly Length right = Length.Of(4).Imperial<Foot>();
private static readonly Volume left = Volume.Of(32, Metric<Centi, Litre>());
private static readonly Length right = Length.Of(4, Imperial<Foot>());
private static readonly nVolume nLeft = nVolume.FromCentiliters(32);
private static readonly nLength nRight = nLength.FromFeet(4);

Expand All @@ -28,13 +26,13 @@ public class Division
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
.NET SDK 7.0.113
[Host] : .NET 7.0.13 (7.0.1323.52501), X64 RyuJIT AVX2
DefaultJob : .NET 7.0.13 (7.0.1323.52501), X64 RyuJIT AVX2
| Method | Mean | Error | StdDev | Ratio | RatioSD | Allocated | Alloc Ratio |
|--------- |---------:|---------:|---------:|------:|--------:|----------:|------------:|
| Quantity | 12.06 ns | 0.055 ns | 0.046 ns | 1.00 | 0.00 | - | NA |
| UnitsNet | 80.38 ns | 0.243 ns | 0.216 ns | 6.66 | 0.03 | - | NA |
| Quantity | 12.70 ns | 0.211 ns | 0.187 ns | 1.00 | 0.00 | - | NA |
| UnitsNet | 81.20 ns | 0.413 ns | 0.386 ns | 6.40 | 0.10 | - | NA |
*/
15 changes: 7 additions & 8 deletions source/Quantities.Benchmark/Compare/Multiplication.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using BenchmarkDotNet.Attributes;
using Quantities.Prefixes;
using Quantities.Units.Imperial.Length;
using Quantities.Units.Si;
Expand All @@ -10,8 +9,8 @@ namespace Quantities.Benchmark.Compare;
[MemoryDiagnoser]
public class Multiplication
{
private static readonly Length left = Length.Of(3).Si<Milli, Metre>();
private static readonly Length right = Length.Of(4).Imperial<Foot>();
private static readonly Length left = Length.Of(3, Si<Milli, Metre>());
private static readonly Length right = Length.Of(4, Imperial<Foot>());
private static readonly nLength nLeft = nLength.FromMillimeters(3);
private static readonly nLength nRight = nLength.FromMillimeters(4);

Expand All @@ -27,13 +26,13 @@ public class Multiplication
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
.NET SDK 7.0.113
[Host] : .NET 7.0.13 (7.0.1323.52501), X64 RyuJIT AVX2
DefaultJob : .NET 7.0.13 (7.0.1323.52501), X64 RyuJIT AVX2
| Method | Mean | Error | StdDev | Ratio | RatioSD | Allocated | Alloc Ratio |
|--------- |---------:|---------:|---------:|------:|--------:|----------:|------------:|
| Quantity | 10.48 ns | 0.052 ns | 0.049 ns | 1.00 | 0.00 | - | NA |
| UnitsNet | 74.90 ns | 0.313 ns | 0.292 ns | 7.14 | 0.05 | - | NA |
| Quantity | 10.80 ns | 0.200 ns | 0.187 ns | 1.00 | 0.00 | - | NA |
| UnitsNet | 74.44 ns | 0.903 ns | 0.845 ns | 6.89 | 0.10 | - | NA |
*/
17 changes: 8 additions & 9 deletions source/Quantities.Benchmark/Compare/ScalarCreation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using BenchmarkDotNet.Attributes;
using Quantities.Prefixes;
using Quantities.Units.Si;

Expand All @@ -12,7 +11,7 @@ public class ScalarCreation
private static readonly Double value = Math.E;

[Benchmark(Baseline = true)]
public Length Quantity() => Length.Of(value).Si<Centi, Metre>();
public Length Quantity() => Length.Of(value, Si<Centi, Metre>());

[Benchmark]
public nLength UnitsNet() => nLength.FromCentimeters(value);
Expand All @@ -23,13 +22,13 @@ public class ScalarCreation
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
.NET SDK 7.0.113
[Host] : .NET 7.0.13 (7.0.1323.52501), X64 RyuJIT AVX2
DefaultJob : .NET 7.0.13 (7.0.1323.52501), X64 RyuJIT AVX2
| Method | Mean | Error | StdDev | Ratio | RatioSD | Allocated | Alloc Ratio |
|--------- |---------:|---------:|---------:|------:|--------:|----------:|------------:|
| Quantity | 10.68 ns | 0.150 ns | 0.141 ns | 1.00 | 0.00 | - | NA |
| UnitsNet | 12.84 ns | 0.139 ns | 0.130 ns | 1.20 | 0.02 | - | NA |
| Method | Mean | Error | StdDev | Ratio | RatioSD | Allocated | Alloc Ratio |
|--------- |----------:|----------:|----------:|------:|--------:|----------:|------------:|
| Quantity | 4.877 ns | 0.0473 ns | 0.0395 ns | 1.00 | 0.00 | - | NA |
| UnitsNet | 12.723 ns | 0.2395 ns | 0.2240 ns | 2.62 | 0.05 | - | NA |
*/
2 changes: 1 addition & 1 deletion source/Quantities.Benchmark/Quantities.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="UnitsNet" Version="5.34.0" />
<PackageReference Include="UnitsNet" Version="5.36.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.8" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.8" Condition="'$(OS)' == 'Windows_NT'" />
</ItemGroup>
Expand Down

0 comments on commit b95d012

Please sign in to comment.