Repository navigation
Expand file tree
/
Copy pathHashMapAddBenchmarks.cs
More file actions
87 lines (74 loc) · 2.15 KB
/
Copy pathHashMapAddBenchmarks.cs
File metadata and controls
87 lines (74 loc) · 2.15 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System.Collections.Generic;
using System.Collections.Immutable;
using BenchmarkDotNet.Attributes;
using LanguageExt.ClassInstances;
using LanguageExt.TypeClasses;
using static LanguageExt.Prelude;
namespace LanguageExt.Benchmarks
{
[RPlotExporter, RankColumn]
[GenericTypeArguments(typeof(int), typeof(OrdInt))]
[GenericTypeArguments(typeof(string), typeof(OrdString))]
public class HashMapAddBenchmarks<T, TOrd>
where TOrd : struct, Ord<T>
{
[Params(100, 1000, 10000, 100000)]
public int N;
Dictionary<T, T> values;
[GlobalSetup]
public void Setup()
{
values = ValuesGenerator.Default.GenerateDictionary<T, T>(N);
}
[Benchmark]
public ImmutableDictionary<T, T> SysColImmutableDictionary()
{
var map = ImmutableDictionary.Create<T, T>();
foreach (var kvp in values)
{
map = map.Add(kvp.Key, kvp.Value);
}
return map;
}
[Benchmark]
public ImmutableSortedDictionary<T, T> SysColImmutableSortedDictionary()
{
var map = ImmutableSortedDictionary.Create<T, T>();
foreach (var kvp in values)
{
map = map.Add(kvp.Key, kvp.Value);
}
return map;
}
[Benchmark]
public Dictionary<T, T> SysColDictionary()
{
var map = new Dictionary<T, T>();
foreach (var kvp in values)
{
map.Add(kvp.Key, kvp.Value);
}
return map;
}
[Benchmark]
public HashMap<TOrd, T, T> LangExtHashMap()
{
var map = HashMap<TOrd, T, T>();
foreach (var kvp in values)
{
map = map.Add(kvp.Key, kvp.Value);
}
return map;
}
[Benchmark]
public Map<TOrd, T, T> LangExtMap()
{
var map = Map<TOrd, T, T>();
foreach (var kvp in values)
{
map = map.Add(kvp.Key, kvp.Value);
}
return map;
}
}
}