-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSelect.cs
More file actions
57 lines (50 loc) · 1.36 KB
/
Select.cs
File metadata and controls
57 lines (50 loc) · 1.36 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
using System.Linq;
using BenchmarkDotNet.Attributes;
namespace StructLinq.Benchmark
{
[MemoryDiagnoser]
public class Select
{
private const int Count = 10000;
public Select()
{
}
[Benchmark(Baseline = true)]
public double SysSelect()
{
return Enumerable.Range(0, Count).Select(x=> x * 2.0).Sum();
}
[Benchmark]
public double DelegateSelect()
{
return StructEnumerable
.Range(0, Count)
.Select(x => x * 2.0)
.Sum();
}
[Benchmark]
public double StructSelect()
{
var multFunction = new MultFunction();
return StructEnumerable.Range(0, Count)
.Select(ref multFunction, x=>x, x => x)
.Sum(x=> x);
}
[Benchmark]
public double ConvertSelect()
{
var multFunction = new MultFunction();
return Enumerable.Range(0, Count)
.ToStructEnumerable()
.Select(ref multFunction, x => x, x=> x)
.Sum(x=>x);
}
}
readonly struct MultFunction : IFunction<int, double>
{
public double Eval(int element)
{
return element * 2.0;
}
}
}