forked from NetFabric/LinqBenchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListInt32Contains.cs
More file actions
78 lines (68 loc) · 1.96 KB
/
ListInt32Contains.cs
File metadata and controls
78 lines (68 loc) · 1.96 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
using BenchmarkDotNet.Attributes;
using JM.LinqFaster;
using JM.LinqFaster.SIMD;
using NetFabric.Hyperlinq;
using StructLinq;
using System.Linq;
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 Linq()
=> System.Linq.Enumerable
.Contains(source, value);
[Benchmark]
public bool LinqFaster()
=> source
.ContainsF(value);
[Benchmark]
public bool LinqAF()
=> global::LinqAF.ListExtensionMethods.Contains(source, value);
[Benchmark]
public bool StructLinq()
=> source
.ToStructEnumerable()
.Contains(value);
[Benchmark]
public bool StructLinq_IFunction()
=> source
.ToStructEnumerable()
.Contains(value, x => x);
[Benchmark]
public bool Hyperlinq()
=> source
.AsValueEnumerable()
.Contains(value);
[Benchmark]
public bool Hyperlinq_SIMD()
=> source
.AsValueEnumerable()
.ContainsVector(value);
}
}