forked from angularsen/UnitsNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertValueBenchmarks.cs
More file actions
57 lines (47 loc) · 1.48 KB
/
Copy pathConvertValueBenchmarks.cs
File metadata and controls
57 lines (47 loc) · 1.48 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
56
57
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
namespace UnitsNet.Benchmark.Conversions.ToValue;
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net48)]
[SimpleJob(RuntimeMoniker.Net80)]
public class ConvertValueBenchmarks
{
private static readonly double Value = 123.456;
[Benchmark(Baseline = true)]
public double ConvertWithConverter()
{
double result = default;
foreach (QuantityInfo quantityInfo in Quantity.Infos)
{
foreach (UnitInfo fromUnitInfo in quantityInfo.UnitInfos)
{
foreach (UnitInfo toUnitInfo in quantityInfo.UnitInfos)
{
result = UnitConverter.Convert(Value, fromUnitInfo.Value, toUnitInfo.Value);
}
}
}
return result;
}
[Benchmark(Baseline = false)]
public double ConvertFromQuantity()
{
double result = default;
foreach (QuantityInfo quantityInfo in Quantity.Infos)
{
foreach (UnitInfo fromUnitInfo in quantityInfo.UnitInfos)
{
foreach (UnitInfo toUnitInfo in quantityInfo.UnitInfos)
{
result = Quantity.From(Value, fromUnitInfo.Value).As(toUnitInfo.Value);
}
}
}
return result;
}
[GlobalSetup]
public void PrepareTo_ConvertWith_FullyCachedFrozenDictionary()
{
var nbQuantities = Quantity.Infos.Count;
}
}