Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare with Units.Net run on a linux box #57

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions source/Quantities.Benchmark/Compare/Creation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using BenchmarkDotNet.Configs;
using Quantities.Prefixes;
using Quantities.Units.Si;
using Quantities.Units.Si.Metric;

using static Towel.Measurements.MeasurementsSyntax;

namespace Quantities.Benchmark.Compare;

[MemoryDiagnoser]
[CategoriesColumn]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
public class Creation
{
private const String Scalar = nameof(Scalar);
private const String Cubed = nameof(Cubed);
private const String Aliasing = nameof(Aliasing);
private static readonly Double value = Math.E;

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

[BenchmarkCategory(Scalar), Benchmark]
public UnitsNet.Length CreateScalarUnitsNet() => UnitsNet.Length.FromCentimeters(value);

[BenchmarkCategory(Scalar), Benchmark]
public QuantityTypes.Length CreateScalarQuantityTypes() => value * QuantityTypes.Length.Centimetre;

[BenchmarkCategory(Scalar), Benchmark]
public Towel.Measurements.Length<Double> CreateScalarTowelMeasurements() => (value, Centimeters);

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

[BenchmarkCategory(Cubed), Benchmark]
public UnitsNet.Volume CreateCubedUnitsNet() => UnitsNet.Volume.FromCubicCentimeters(value);

[BenchmarkCategory(Cubed), Benchmark]
public QuantityTypes.Volume CreateCubedQuantityTypes() => value * QuantityTypes.Volume.CubicCentimetre;

[BenchmarkCategory(Cubed), Benchmark]
public Towel.Measurements.Volume<Double> CreateCubedTowelMeasurement() => (value, Centimeters * Centimeters * Centimeters);

[BenchmarkCategory(Aliasing), Benchmark(Baseline = true)]
public Volume CreateAliasedQuantity() => Volume.Of(value, Metric<Centi, Litre>());

[BenchmarkCategory(Aliasing), Benchmark]
public UnitsNet.Volume CreateAliasedUnitsNet() => UnitsNet.Volume.FromCentiliters(value);

[BenchmarkCategory(Aliasing), Benchmark]
public QuantityTypes.Volume CreateAliasedQuantityTypes() => value * QuantityTypes.Volume.Litre / 100; // cannot create centilitres...

[BenchmarkCategory(Aliasing), Benchmark]
public Towel.Measurements.Volume<Double> CreateAliasedTowelMeasurements() => (1000 * value, Millimeters * Millimeters * Millimeters); // cannot create litres...
}

/* Summary *

BenchmarkDotNet v0.13.12, Arch Linux
Intel Core i7-8565U CPU 1.80GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores
.NET SDK 8.0.103
[Host] : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2


| Method | Categories | Mean | Error | Ratio | Allocated | Alloc Ratio |
|------------------------------- |----------- |-----------:|----------:|-------:|----------:|------------:|
| CreateAliasedQuantity | Aliasing | 13.0551 ns | 0.1992 ns | 1.000 | - | NA |
| CreateAliasedUnitsNet | Aliasing | 11.8207 ns | 0.0689 ns | 0.906 | - | NA |
| CreateAliasedQuantityTypes | Aliasing | 0.0018 ns | 0.0059 ns | 0.000 | - | NA |
| CreateAliasedTowelMeasurements | Aliasing | 0.0728 ns | 0.0298 ns | 0.006 | - | NA |
| | | | | | | |
| CreateCubedQuantity | Cubed | 0.7939 ns | 0.0129 ns | 1.000 | - | NA |
| CreateCubedUnitsNet | Cubed | 11.8563 ns | 0.0491 ns | 14.906 | - | NA |
| CreateCubedQuantityTypes | Cubed | 0.0000 ns | 0.0000 ns | 0.000 | - | NA |
| CreateCubedTowelMeasurement | Cubed | 0.0975 ns | 0.0216 ns | 0.123 | - | NA |
| | | | | | | |
| CreateScalarQuantity | Scalar | 0.7578 ns | 0.0110 ns | 1.000 | - | NA |
| CreateScalarUnitsNet | Scalar | 11.7537 ns | 0.0513 ns | 15.513 | - | NA |
| CreateScalarQuantityTypes | Scalar | 0.0038 ns | 0.0061 ns | 0.005 | - | NA |
| CreateScalarTowelMeasurements | Scalar | 0.0634 ns | 0.0092 ns | 0.085 | - | NA |
*/
56 changes: 56 additions & 0 deletions source/Quantities.Benchmark/Compare/Division.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Quantities.Prefixes;
using Quantities.Units.Imperial.Length;
using Quantities.Units.Si.Metric;

using nLength = UnitsNet.Length;
using nVolume = UnitsNet.Volume;
using qtArea = QuantityTypes.Area;
using qtVolume = QuantityTypes.Volume;
using tLength = Towel.Measurements.Length<System.Double>;
using tVolume = Towel.Measurements.Volume<System.Double>;

using static Towel.Measurements.MeasurementsSyntax;

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 nVolume nLeft = nVolume.FromCentiliters(32);
private static readonly nLength nRight = nLength.FromFeet(4);
private static readonly qtVolume qtLeft = 32 * qtVolume.Litre / 100;
private static readonly qtArea qtRight = 4 * qtArea.Acre;
private static readonly tVolume tLeft = (32 * 10, Centimeters * Centimeters * Centimeters);
private static readonly tLength tRight = (4, Feet);

[Benchmark(Baseline = true)]
public Area Quantity() => left / right;

[Benchmark]
public UnitsNet.Area UnitsNet() => nLeft / nRight;

[Benchmark]
public QuantityTypes.Length QuantityTypes() => qtLeft / qtRight; // cannot divide volume by area :-/

[Benchmark]
public Towel.Measurements.Area<Double> TowelMeasurements() => tLeft / tRight;
}

/* Summary *

BenchmarkDotNet v0.13.12, Arch Linux
Intel Core i7-8565U CPU 1.80GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores
.NET SDK 8.0.103
[Host] : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2


| Method | Mean | Error | Ratio | Allocated | Alloc Ratio |
|------------------ |----------:|----------:|------:|----------:|------------:|
| Quantity | 8.259 ns | 0.0330 ns | 1.00 | - | NA |
| UnitsNet | 47.356 ns | 0.6768 ns | 5.75 | - | NA |
| QuantityTypes | 1.734 ns | 0.0055 ns | 0.21 | - | NA |
| TowelMeasurements | 8.630 ns | 0.0247 ns | 1.04 | - | NA |
*/
54 changes: 54 additions & 0 deletions source/Quantities.Benchmark/Compare/Multiplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Quantities.Prefixes;
using Quantities.Units.Imperial.Length;
using Quantities.Units.Si;

using nLength = UnitsNet.Length;
using qtLength = QuantityTypes.Length;
using tLength = Towel.Measurements.Length<System.Double>;

using static Towel.Measurements.MeasurementsSyntax;

namespace Quantities.Benchmark.Compare;

[MemoryDiagnoser(displayGenColumns: false)]
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 nLength nLeft = nLength.FromMillimeters(3);
private static readonly nLength nRight = nLength.FromMillimeters(4);
private static readonly qtLength qtLeft = 3 * qtLength.Millimetre;
private static readonly qtLength qtRight = 4 * qtLength.Foot;
private static readonly tLength tLeft = (3d, Millimeters);
private static readonly tLength tRight = (4d, Feet);


[Benchmark(Baseline = true)]
public Area Quantity() => left * right;

[Benchmark]
public UnitsNet.Area UnitsNet() => nLeft * nRight;

[Benchmark]
public QuantityTypes.Area QuantityTypes() => qtLeft * qtRight;

[Benchmark]
public Towel.Measurements.Area<Double> TowelMeasurements() => tLeft * tRight;
}

/* Summary *

BenchmarkDotNet v0.13.12, Arch Linux
Intel Core i7-8565U CPU 1.80GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores
.NET SDK 8.0.103
[Host] : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2


| Method | Mean | Error | Ratio | Allocated | Alloc Ratio |
|------------------ |-----------:|----------:|------:|----------:|------------:|
| Quantity | 6.8138 ns | 0.0566 ns | 1.000 | - | NA |
| UnitsNet | 42.8554 ns | 0.3723 ns | 6.290 | - | NA |
| QuantityTypes | 0.0006 ns | 0.0024 ns | 0.000 | - | NA |
| TowelMeasurements | 6.2112 ns | 0.0824 ns | 0.912 | - | NA |
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using BenchmarkDotNet.Configs;
using Quantities.Prefixes;
using Quantities.Units.Imperial.Length;
using Quantities.Units.Si;
using UnitsNet.Units;

using nLength = UnitsNet.Length;
using qtLength = QuantityTypes.Length;
using tLength = Towel.Measurements.Length<System.Double>;

using static Towel.Measurements.MeasurementsSyntax;

namespace Quantities.Benchmark.Compare;

[MemoryDiagnoser(displayGenColumns: false)]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
public class QuantityConversionComparison
{
private const String ToSi = nameof(ToSi);
private const String ToImperial = nameof(ToImperial);
private const String ToSame = nameof(ToSame);
private static readonly Length si = Length.Of(3, Si<Milli, Metre>());
private static readonly Length imperial = Length.Of(4, Imperial<Foot>());
private static readonly nLength nSi = nLength.FromMillimeters(3);
private static readonly nLength nImperial = nLength.FromFeet(4);
private static readonly qtLength qtSi = 3 * qtLength.Millimetre;
private static readonly qtLength qtImperial = 4 * qtLength.Foot;
private static readonly tLength tSi = (3d, Millimeters);
private static readonly tLength tImperial = (4d, Feet);

[BenchmarkCategory(ToSi), Benchmark(Baseline = true)]
public Length QuantityToSi() => imperial.To(Si<Milli, Metre>());
[BenchmarkCategory(ToSi), Benchmark]
public nLength UnitsNetToSi() => nImperial.ToUnit(LengthUnit.Millimeter);
[BenchmarkCategory(ToSi), Benchmark]
public qtLength QuantityTypesToSi() => qtImperial.ConvertTo(qtLength.Millimetre) * qtLength.Millimetre;
[BenchmarkCategory(ToSi), Benchmark]
public tLength TowelMeasurementsToSi() => (tImperial[Millimeters], Millimeters);

[BenchmarkCategory(ToImperial), Benchmark(Baseline = true)]
public Length QuantityToImperial() => si.To(Imperial<Foot>());
[BenchmarkCategory(ToImperial), Benchmark]
public nLength UnitsNetToImperial() => nSi.ToUnit(LengthUnit.Foot);
[BenchmarkCategory(ToImperial), Benchmark]
public qtLength QuantityTypesToImperial() => qtSi.ConvertTo(qtLength.Foot) * qtLength.Foot;
[BenchmarkCategory(ToImperial), Benchmark]
public tLength TowelMeasurementsToImperial() => (tSi[Feet], Feet);

[BenchmarkCategory(ToSame), Benchmark(Baseline = true)]
public Length QuantityToSame() => imperial.To(Imperial<Foot>());
[BenchmarkCategory(ToSame), Benchmark]
public nLength UnitsNetToSame() => nImperial.ToUnit(LengthUnit.Foot);
[BenchmarkCategory(ToSame), Benchmark]
public qtLength QuantityTypesToSame() => qtImperial.ConvertTo(qtLength.Foot) * qtLength.Foot;
[BenchmarkCategory(ToSame), Benchmark]
public tLength TowelMeasurementsToSame() => (tImperial[Feet], Feet);
}

/* Summary *

BenchmarkDotNet v0.13.12, Arch Linux
Intel Core i7-8565U CPU 1.80GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores
.NET SDK 8.0.103
[Host] : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2


| Method | Mean | Error | Ratio | Allocated | Alloc Ratio |
|---------------------------- |-----------:|----------:|-------:|----------:|------------:|
| QuantityToImperial | 2.7528 ns | 0.0701 ns | 1.000 | - | NA |
| UnitsNetToImperial | 76.2580 ns | 0.5021 ns | 27.712 | 48 B | NA |
| QuantityTypesToImperial | 0.0049 ns | 0.0084 ns | 0.002 | - | NA |
| TowelMeasurementsToImperial | 3.9093 ns | 0.0157 ns | 1.421 | - | NA |
| | | | | | |
| QuantityToSame | 2.5044 ns | 0.0480 ns | 1.000 | - | NA |
| UnitsNetToSame | 16.1036 ns | 0.0959 ns | 6.432 | - | NA |
| QuantityTypesToSame | 0.0028 ns | 0.0079 ns | 0.001 | - | NA |
| TowelMeasurementsToSame | 0.0340 ns | 0.0060 ns | 0.013 | - | NA |
| | | | | | |
| QuantityToSi | 3.6184 ns | 0.0270 ns | 1.000 | - | NA |
| UnitsNetToSi | 75.7462 ns | 0.2194 ns | 20.934 | 48 B | NA |
| QuantityTypesToSi | 0.0038 ns | 0.0056 ns | 0.001 | - | NA |
| TowelMeasurementsToSi | 3.4991 ns | 0.0125 ns | 0.967 | - | NA |
*/
83 changes: 83 additions & 0 deletions source/Quantities.Benchmark/Compare/ValueConversionComparison.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using BenchmarkDotNet.Configs;
using Quantities.Prefixes;
using Quantities.Units.Imperial.Length;
using Quantities.Units.Si;

using nLength = UnitsNet.Length;
using qtLength = QuantityTypes.Length;
using tLength = Towel.Measurements.Length<System.Double>;

using static Towel.Measurements.MeasurementsSyntax;

namespace Quantities.Benchmark.Compare;

[MemoryDiagnoser(displayGenColumns: false)]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
public class ValueConversionComparison
{
private const String ToSi = nameof(ToSi);
private const String ToImperial = nameof(ToImperial);
private const String ToSame = nameof(ToSame);
private static readonly Length si = Length.Of(3, Si<Milli, Metre>());
private static readonly Length imperial = Length.Of(4, Imperial<Foot>());
private static readonly nLength nSi = nLength.FromMillimeters(3);
private static readonly nLength nImperial = nLength.FromFeet(4);
private static readonly qtLength qtSi = 3 * qtLength.Millimetre;
private static readonly qtLength qtImperial = 4 * qtLength.Foot;
private static readonly tLength tSi = (3d, Millimeters);
private static readonly tLength tImperial = (4d, Feet);

[BenchmarkCategory(ToSi), Benchmark(Baseline = true)]
public Double QuantityToSi() => imperial.To(Si<Milli, Metre>());
[BenchmarkCategory(ToSi), Benchmark]
public Double UnitsNetToSi() => nImperial.Millimeters;
[BenchmarkCategory(ToSi), Benchmark]
public Double QuantityTypesToSi() => qtImperial.ConvertTo(qtLength.Millimetre);
[BenchmarkCategory(ToSi), Benchmark]
public Double TowelMeasurementsToSi() => tImperial[Millimeters];

[BenchmarkCategory(ToImperial), Benchmark(Baseline = true)]
public Double QuantityToImperial() => si.To(Imperial<Foot>());
[BenchmarkCategory(ToImperial), Benchmark]
public Double UnitsNetToImperial() => nSi.Feet;
[BenchmarkCategory(ToImperial), Benchmark]
public Double QuantityTypesToImperial() => qtSi.ConvertTo(qtLength.Foot);
[BenchmarkCategory(ToImperial), Benchmark]
public Double TowelMeasurementsToImperial() => tSi[Feet];

[BenchmarkCategory(ToSame), Benchmark(Baseline = true)]
public Double QuantityToSame() => imperial.To(Imperial<Foot>());
[BenchmarkCategory(ToSame), Benchmark]
public Double UnitsNetToSame() => nImperial.Feet;
[BenchmarkCategory(ToSame), Benchmark]
public Double QuantityTypesToSame() => qtImperial.ConvertTo(qtLength.Foot);
[BenchmarkCategory(ToSame), Benchmark]
public Double TowelMeasurementsToSame() => tImperial[Feet];
}

/* Summary *

BenchmarkDotNet v0.13.12, Arch Linux
Intel Core i7-8565U CPU 1.80GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores
.NET SDK 8.0.103
[Host] : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2


| Method | Mean | Error | Ratio | Allocated | Alloc Ratio |
|---------------------------- |-----------:|----------:|-------:|----------:|------------:|
| QuantityToImperial | 3.5543 ns | 0.0593 ns | 1.00 | - | NA |
| UnitsNetToImperial | 80.8526 ns | 1.5024 ns | 22.78 | 48 B | NA |
| QuantityTypesToImperial | 0.0746 ns | 0.0038 ns | 0.02 | - | NA |
| TowelMeasurementsToImperial | 3.6869 ns | 0.0139 ns | 1.04 | - | NA |
| | | | | | |
| QuantityToSame | 1.2234 ns | 0.0062 ns | 1.000 | - | NA |
| UnitsNetToSame | 0.4822 ns | 0.0077 ns | 0.394 | - | NA |
| QuantityTypesToSame | 0.0184 ns | 0.0041 ns | 0.015 | - | NA |
| TowelMeasurementsToSame | 0.0004 ns | 0.0009 ns | 0.000 | - | NA |
| | | | | | |
| QuantityToSi | 3.5698 ns | 0.0140 ns | 1.000 | - | NA |
| UnitsNetToSi | 82.4369 ns | 0.4410 ns | 23.109 | 48 B | NA |
| QuantityTypesToSi | 0.0000 ns | 0.0000 ns | 0.000 | - | NA |
| TowelMeasurementsToSi | 4.3121 ns | 0.0674 ns | 1.216 | - | NA |
*/
3 changes: 3 additions & 0 deletions source/Quantities.Benchmark/Quantities.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="UnitsNet" Version="5.49.0" />
<PackageReference Include="QuantityTypes" Version="5.0.0" />
<PackageReference Include="Towel" Version="1.0.40" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
</ItemGroup>

Expand Down
Loading