forked from NetFabric/LinqBenchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnumerableInt32WhereCount.cs
65 lines (57 loc) · 1.67 KB
/
EnumerableInt32WhereCount.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
using BenchmarkDotNet.Attributes;
using com.tinyield;
using NetFabric.Hyperlinq;
using StructLinq;
using System.Linq;
namespace LinqBenchmarks.Enumerable.Int32
{
public class EnumerableInt32WhereCount: EnumerableInt32BenchmarkBase
{
[Benchmark(Baseline = true)]
public int ForeachLoop()
{
var count = 0;
foreach (var item in source)
{
if (item.IsEven())
count++;
}
return count;
}
[Benchmark]
public int Linq()
=> source.Count(item => item.IsEven());
[Benchmark]
public int LinqAF()
=> global::LinqAF.IEnumerableExtensionMethods.Count(source, item => item.IsEven());
[Benchmark]
public int StructLinq()
=> source
.ToStructEnumerable()
.Where(item => item.IsEven())
.Count();
[Benchmark]
public int StructLinq_IFunction()
{
var predicate = new Int32IsEven();
return source
.ToStructEnumerable()
.Where(ref predicate, x => x)
.Count(x => x);
}
[Benchmark]
public int Hyperlinq()
=> source.AsValueEnumerable()
.Where(item => item.IsEven())
.Count();
[Benchmark]
public int Hyperlinq_IFunction()
=> source.AsValueEnumerable()
.Where<Int32IsEven>()
.Count();
[Benchmark]
public long Tinyield() => Query.FromEnumerable(source)
.Filter(i => i.IsEven())
.Count();
}
}