-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathArrayInt32SelectToList.cs
98 lines (84 loc) · 2.44 KB
/
ArrayInt32SelectToList.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
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
98
namespace LinqBenchmarks.Array.Int32;
public class ArrayInt32SelectToList: ArrayInt32BenchmarkBase
{
[Benchmark(Baseline = true)]
public List<int> ForLoop()
{
var list = new List<int>();
var array = source;
for (var index = 0; index < array.Length; index++)
{
var item = array[index];
list.Add(item * 3);
}
return list;
}
[Benchmark]
public List<int> ForeachLoop()
{
var list = new List<int>();
foreach (var item in source)
{
list.Add(item * 3);
}
return list;
}
[Benchmark]
public List<int> Linq()
=> source
.Select(item => item * 3)
.ToList();
[Benchmark]
public List<int> LinqFaster()
=> new(source.SelectF(item => item * 3));
[Benchmark]
public List<int> LinqFaster_SIMD()
=> new(source.SelectS(item => item * 3, item => item * 3));
[Benchmark]
public List<int> LinqFasterer()
=> EnumerableF.ToListF(EnumerableF.SelectF(source, item => item * 3));
[Benchmark]
public List<int> LinqAF()
=> global::LinqAF.ArrayExtensionMethods
.Select(source, item => item * 3)
.ToList();
[Benchmark]
public List<int> StructLinq()
=> source.ToStructEnumerable()
.Select(item => item * 3)
.ToList();
[Benchmark]
public List<int> StructLinq_ValueDelegate()
{
var selector = new TripleOfInt32();
return source.ToStructEnumerable()
.Select(ref selector, x => x, x => x)
.ToList();
}
[Benchmark]
public List<int> Hyperlinq()
=> source.AsValueEnumerable()
.Select(item => item * 3)
.ToList();
[Benchmark]
public List<int> Hyperlinq_ValueDelegate()
=> source.AsValueEnumerable()
.Select<int, TripleOfInt32>()
.ToList();
[Benchmark]
public List<int> Hyperlinq_SIMD()
=> source.AsValueEnumerable()
.SelectVector(item => item * 3, item => item * 3)
.ToList();
[Benchmark]
public List<int> Hyperlinq_ValueDelegate_SIMD()
=> source.AsValueEnumerable()
.SelectVector<int, int, TripleOfInt32>()
.ToList();
[Benchmark]
public List<int> Faslinq()
=> FaslinqExtensions.Select(
source,
item => item * 3)
.ToList();
}