-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSelectCount.cs
More file actions
97 lines (83 loc) · 2 KB
/
SelectCount.cs
File metadata and controls
97 lines (83 loc) · 2 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
87
88
89
90
91
92
93
94
95
96
97
// LinqGen.Benchmarks, Maxwell Keonwoo Kang <code.athei@gmail.com>, 2022
using BenchmarkDotNet.Attributes;
using Cathei.LinqGen;
using StructLinq;
using NetFabric.Hyperlinq;
namespace Cathei.LinqGen.Benchmarks.Cases;
[MemoryDiagnoser]
public class SelectCount
{
private const int Count = 10_000;
[Benchmark(Baseline = true)]
public double Linq()
{
return Enumerable
.Range(0, Count)
.Select(x=> x * 2.0)
.Count();
}
[Benchmark]
public double LinqGenDelegate()
{
return Gen.Enumerable
.Range(0, Count)
.Select(x => x * 2.0)
.Count();
}
[Benchmark]
public double LinqGenStruct()
{
var selector = new Selector();
return Gen.Enumerable
.Range(0, Count)
.Select(selector)
.Count();
}
[Benchmark]
public double StructLinqDelegate()
{
return StructEnumerable
.Range(0, Count)
.Select(x => x * 2.0)
.Count();
}
[Benchmark]
public double StructLinqStruct()
{
var selector = new Selector();
return StructEnumerable
.Range(0, Count)
.Select(ref selector, x => x, x => x)
.Count(x=> x);
}
[Benchmark]
public double HyperLinqDelegate()
{
return ValueEnumerable
.Range(0, Count)
.Select(x => x * 2.0)
.Count();
}
[Benchmark]
public double HyperLinqStruct()
{
return ValueEnumerable
.Range(0, Count)
.Select<double, Selector>()
.Count();
}
readonly struct Selector :
StructLinq.IFunction<int, double>,
NetFabric.Hyperlinq.IFunction<int, double>,
IStructFunction<int, double>
{
public double Eval(int element)
{
return element * 2.0;
}
public double Invoke(int arg)
{
return arg * 2.0;
}
}
}