-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeserializationBenchmark.cs
More file actions
55 lines (47 loc) · 2.82 KB
/
Copy pathDeserializationBenchmark.cs
File metadata and controls
55 lines (47 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using Quantities.Prefixes;
using Quantities.Units.Si;
using Quantities.Units.Si.Derived;
using Quantities.Units.Si.Metric;
namespace Quantities.Benchmark;
[MemoryDiagnoser(displayGenColumns: false)]
public class DeserializationBenchmark
{
private static readonly String triple = Triple().Serialize();
private static readonly String simpleQuantity = Length.Of(Math.PI, Si<Metre>()).Serialize();
private static readonly String prefixedQuantity = Length.Of(Math.PI, Si<Kilo, Metre>()).Serialize();
private static readonly String fractionalQuantity = Velocity.Of(Math.PI, Si<Kilo, Metre>().Per(Metric<Hour>())).Serialize();
private static readonly String multiplicativeQuantity = Energy.Of(Math.PI, Si<Kilo, Watt>().Times(Metric<Hour>())).Serialize();
private static readonly String powerQuantity = Volume.Of(Math.PI, Cubic(Si<Deci, Metre>())).Serialize();
private static readonly String scalarPowerQuantity = Volume.Of(Math.PI, Metric<Deci, Litre>()).Serialize();
[Benchmark(Baseline = true)]
public (Double, String, String) SystemTriple() => triple.Deserialize<(Double, String, String)>();
[Benchmark]
public Length SystemQuantity() => simpleQuantity.Deserialize<Length>();
[Benchmark]
public Length PrefixedQuantity() => prefixedQuantity.Deserialize<Length>();
[Benchmark]
public Velocity FractionalQuantity() => fractionalQuantity.Deserialize<Velocity>();
[Benchmark]
public Energy MultiplicativeQuantity() => multiplicativeQuantity.Deserialize<Energy>();
[Benchmark]
public Volume PowerQuantity() => powerQuantity.Deserialize<Volume>();
[Benchmark]
public Volume ScalarPowerQuantity() => scalarPowerQuantity.Deserialize<Volume>();
private static (Double value, String prefix, String unit) Triple() => (Math.PI, "K", "m");
}
/* Summary *
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3007/23H2/2023Update/SunValley3)
12th Gen Intel Core i7-1260P, 1 CPU, 16 logical and 12 physical cores
.NET SDK 8.0.101
[Host] : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2
| Method | Mean | Error | Ratio | Allocated | Alloc Ratio |
|----------------------- |----------:|----------:|------:|----------:|------------:|
| SystemTriple | 88.86 ns | 1.264 ns | 1.00 | 40 B | 1.00 |
| SystemQuantity | 317.09 ns | 3.436 ns | 3.57 | 160 B | 4.00 |
| PrefixedQuantity | 363.72 ns | 3.821 ns | 4.09 | 224 B | 5.60 |
| FractionalQuantity | 702.82 ns | 6.623 ns | 7.88 | 744 B | 18.60 |
| MultiplicativeQuantity | 696.38 ns | 13.537 ns | 7.83 | 744 B | 18.60 |
| PowerQuantity | 587.81 ns | 6.686 ns | 6.63 | 592 B | 14.80 |
| ScalarPowerQuantity | 435.96 ns | 3.718 ns | 4.90 | 232 B | 5.80 |
*/