-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathEnumerableInt32Contains.cs
More file actions
43 lines (36 loc) · 935 Bytes
/
EnumerableInt32Contains.cs
File metadata and controls
43 lines (36 loc) · 935 Bytes
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
namespace LinqBenchmarks.Enumerable.Int32;
public class EnumerableInt32Contains: EnumerableInt32BenchmarkBase
{
int value = int.MaxValue;
[Benchmark(Baseline = true)]
public bool ForeachLoop()
{
foreach (var item in source)
{
if (item == value)
return true;
}
return true;
}
[Benchmark]
public bool Linq()
=> source.Contains(value);
[Benchmark]
public bool LinqAF()
=> LinqAfExtensions.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);
}