Repository navigation
Expand file tree
/
Copy pathHashSetAddBenchmarks.cs
More file actions
86 lines (73 loc) · 2.04 KB
/
Copy pathHashSetAddBenchmarks.cs
File metadata and controls
86 lines (73 loc) · 2.04 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
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 HashSetAddBenchmarks<T, TOrd>
where TOrd : struct, Ord<T>
{
[Params(100, 1000, 10000, 100000)]
public int N;
T[] values;
[GlobalSetup]
public void Setup()
{
values = ValuesGenerator.Default.GenerateUniqueValues<T>(N);
}
[Benchmark]
public ImmutableHashSet<T> SysColImmutableHashSet()
{
var set = ImmutableHashSet.Create<T>();
foreach (var value in values)
{
set = set.Add(value);
}
return set;
}
[Benchmark]
public ImmutableSortedSet<T> SysColImmutableSortedSet()
{
var set = ImmutableSortedSet.Create<T>();
foreach (var value in values)
{
set = set.Add(value);
}
return set;
}
[Benchmark]
public System.Collections.Generic.HashSet<T> SysColHashSet()
{
var set = new System.Collections.Generic.HashSet<T>();
foreach (var value in values)
{
set.Add(value);
}
return set;
}
[Benchmark]
public HashSet<TOrd, T> LangExtHashSet()
{
var set = HashSet<TOrd, T>();
foreach (var value in values)
{
set = set.Add(value);
}
return set;
}
[Benchmark]
public Set<TOrd, T> LangExtSet()
{
var set = Set<TOrd, T>();
foreach (var value in values)
{
set = set.Add(value);
}
return set;
}
}
}