-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForEachVectorExBenchmarks.cs
More file actions
48 lines (39 loc) · 959 Bytes
/
ForEachVectorExBenchmarks.cs
File metadata and controls
48 lines (39 loc) · 959 Bytes
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
using BenchmarkDotNet.Attributes;
using NetFabric;
public class ForEachVectorExBenchmarks
{
int[]? array;
[Params(10, 10_000)]
public int Count { get; set; }
[GlobalSetup]
public void GlobalSetup()
{
var enumerable = Utils.GetEnumerable(Count, 100);
array = enumerable.ToArray();
}
[Benchmark(Baseline = true)]
public int Array_foreach()
{
var sum = 0;
foreach (var item in array!)
sum += item;
return sum;
}
[Benchmark]
public int Array_Sum()
=> array!.Sum();
[Benchmark]
public int Array_ForEachEx_ValueAction()
{
var sum = new SumValueAction<int>();
array!.ForEachEx(ref sum);
return sum.Result;
}
[Benchmark]
public int Array_ForEachEx_ValueVectorAction()
{
var sum = new SumValueAction<int>();
array!.ForEachVectorEx(ref sum);
return sum.Result;
}
}