-
Notifications
You must be signed in to change notification settings - Fork 14
/
ListInt32Contains.cs
84 lines (70 loc) · 1.93 KB
/
ListInt32Contains.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
using ListExtensions = Faslinq.ListExtensions;
namespace LinqBenchmarks.List.Int32;
public partial class ListInt32Contains: Int32ListBenchmarkBase
{
int value = int.MaxValue;
[Benchmark(Baseline = true)]
public bool ForLoop()
{
var array = source;
for (var index = 0; index < array.Count; index++)
{
var item = array[index];
if (item == value)
return true;
}
return true;
}
#pragma warning disable HLQ010 // Consider using a 'for' loop instead.
[Benchmark]
public bool ForeachLoop()
{
foreach (var item in source)
{
if (item == value)
return true;
}
return true;
}
#pragma warning restore HLQ010 // Consider using a 'for' loop instead.
[Benchmark]
public bool List_Exists()
=> source.Exists(item => item == value);
[Benchmark]
public bool Linq()
=> System.Linq.Enumerable
.Contains(source, value);
[Benchmark]
public bool LinqFaster()
=> source
.ContainsF(value);
[Benchmark]
public bool LinqFasterer()
=> EnumerableF.ContainsF(source, value);
[Benchmark]
public bool LinqAF()
=> global::LinqAF.ListExtensionMethods.Contains(source, value);
[Benchmark]
public bool StructLinq()
=> source
.ToStructEnumerable()
.Contains(value);
[Benchmark]
public bool StructLinq_ValueDelegate()
=> source
.ToStructEnumerable()
.Contains(value, x => x);
[Benchmark]
public bool Hyperlinq()
=> source
.AsValueEnumerable()
.Contains(value);
[Benchmark]
public bool Hyperlinq_SIMD()
=> source
.AsValueEnumerable()
.ContainsVector(value);
[Benchmark]
public bool Faslinq()
=> ListExtensions.Any(source, i => i.Equals(value));
}