-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathProgram.cs
62 lines (50 loc) · 1.25 KB
/
Program.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
54
55
56
57
58
59
60
61
62
// Made by Benjamin Abt - https://github.com/BenjaminAbt
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<Benchmark>();
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net70)] // PGO enabled by default
[SimpleJob(RuntimeMoniker.Net80)]
[SimpleJob(RuntimeMoniker.Net90, baseline: true)]
[HideColumns(Column.Job)]
public class Benchmark
{
private int[] _data;
[Params(10, 100, 500)]
public int Count { get; set; }
[GlobalSetup]
public void GlobalSetup()
{
_data = Enumerable.Range(0, Count).ToArray();
}
[Benchmark]
public int ListWrite()
{
List<int> list = new(Count);
Fill(list);
return list.Count;
}
[Benchmark]
public int HashSetWrite()
{
HashSet<int> hashSet = new(Count);
Fill(hashSet);
return hashSet.Count;
}
[Benchmark]
public int ListDistinct()
{
List<int> list = new(Count);
Fill(list);
list.Distinct().ToList();
return list.Count;
}
public void Fill(ICollection<int> source)
{
foreach (int i in _data) { source.Add(i); }
}
}