-
Notifications
You must be signed in to change notification settings - Fork 11
/
HashSet.cs
53 lines (44 loc) · 1.09 KB
/
HashSet.cs
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
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
namespace StructLinq.Benchmark
{
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net48, baseline:true)]
[SimpleJob(RuntimeMoniker.Net60)]
[SimpleJob(RuntimeMoniker.Net70)]
public class HashSet
{
private HashSet<int> hashset;
[Params(2, 100, 1000)]
public int ItemCount { get; set; }
[GlobalSetup]
public void GlobalSetup()
{
hashset = Enumerable
.Range(0, ItemCount)
.ToHashSet();
}
[Benchmark(Baseline = true)]
public int LINQ()
{
var sum = 0;
foreach (var i in hashset)
{
sum += i;
}
return sum;
}
[Benchmark]
public int StructLINQ()
{
var sum = 0;
foreach (var i in hashset.ToStructEnumerable())
{
sum += i;
}
return sum;
}
}
}