|
1 |
| -using BenchmarkDotNet.Attributes; |
2 |
| -using BenchmarkDotNet.Configs; |
3 |
| -using BenchmarkDotNet.Order; |
| 1 | +using BenchmarkDotNet.Configs; |
4 | 2 | using BenchmarkDotNet.Reports;
|
5 | 3 | using BenchmarkDotNet.Running;
|
6 |
| -using Perfolizer.Horology; |
7 | 4 | using Cathei.LinqGen;
|
| 5 | +using Perfolizer.Horology; |
8 | 6 | using SpanLinq;
|
9 |
| -using StructLinq; |
10 | 7 | using ZLinq;
|
11 |
| -using ZLinq.Linq; |
12 |
| -using Benchmark; |
13 |
| - |
14 |
| -#if !DEBUG |
15 |
| - |
16 |
| -//BenchmarkRunner.Run<IterateBenchmark>(DefaultConfig.Instance.WithSummaryStyle(SummaryStyle.Default.WithTimeUnit(TimeUnit.Millisecond)), args); |
17 |
| -//BenchmarkRunner.Run<SimdRange>(DefaultConfig.Instance.WithSummaryStyle(SummaryStyle.Default.WithTimeUnit(TimeUnit.Millisecond)), args); |
18 |
| -//BenchmarkRunner.Run<SimdSelect>(DefaultConfig.Instance.WithSummaryStyle(SummaryStyle.Default.WithTimeUnit(TimeUnit.Millisecond)), args); |
19 |
| -//BenchmarkRunner.Run<LookupBattle>(DefaultConfig.Instance.WithSummaryStyle(SummaryStyle.Default.WithTimeUnit(TimeUnit.Millisecond)), args); |
20 |
| -// BenchmarkRunner.Run<CopyBattle>(DefaultConfig.Instance.WithSummaryStyle(SummaryStyle.Default.WithTimeUnit(TimeUnit.Millisecond)), args); |
21 |
| - |
22 |
| -// BenchmarkRunner.Run<SimdSum>(DefaultConfig.Instance.WithSummaryStyle(SummaryStyle.Default), args); |
23 |
| -//BenchmarkRunner.Run<SimdSumUnsigned>(DefaultConfig.Instance.WithSummaryStyle(SummaryStyle.Default), args); |
24 |
| - |
25 |
| -//BenchmarkRunner.Run<SimdAny>(DefaultConfig.Instance.WithSummaryStyle(SummaryStyle.Default), args); |
26 |
| - |
27 |
| - |
28 |
| -//BenchmarkRunner.Run<ReadMeBenchmark>(DefaultConfig.Instance.WithSummaryStyle(SummaryStyle.Default), args); |
29 |
| - |
30 |
| -//BenchmarkRunner.Run<LinqPerfBenchmarks.AggregateBy00>(DefaultConfig.Instance, args); |
31 |
| -//BenchmarkRunner.Run<LinqPerfBenchmarks.Count00>(DefaultConfig.Instance, args); |
32 |
| -//BenchmarkRunner.Run<LinqPerfBenchmarks.CountBy00>(DefaultConfig.Instance, args); |
33 |
| -//BenchmarkRunner.Run<LinqPerfBenchmarks.GroupBy00>(DefaultConfig.Instance, args); |
34 |
| -//BenchmarkRunner.Run<LinqPerfBenchmarks.Order00>(DefaultConfig.Instance, args); |
35 |
| -BenchmarkRunner.Run<LinqPerfBenchmarks.Where00>(DefaultConfig.Instance, args); |
36 |
| -//BenchmarkRunner.Run<LinqPerfBenchmarks.Where01>(DefaultConfig.Instance, args); |
37 |
| -#else |
38 |
| - |
39 |
| -BenchmarkRunner.Run<IterateBenchmark>(DefaultConfig.Instance.WithSummaryStyle(SummaryStyle.Default.WithTimeUnit(TimeUnit.Millisecond)), args); |
40 |
| - |
41 |
| -var i = 0; |
42 |
| -foreach (var item in typeof(Enumerable).GetMethods().GroupBy(x => x.Name)) |
43 |
| -{ |
44 |
| - Console.WriteLine($"- [ ] {item.Key}"); |
45 |
| - i++; |
46 |
| -} |
47 |
| -Console.WriteLine(i); |
48 | 8 |
|
| 9 | +namespace Benchmark; |
49 | 10 |
|
50 |
| -#endif |
51 | 11 |
|
52 |
| -[ShortRunJob] |
53 |
| -[MemoryDiagnoser] |
54 |
| -[Orderer(SummaryOrderPolicy.FastestToSlowest)] |
55 |
| -public class IterateBenchmark |
| 12 | +internal static class Program |
56 | 13 | {
|
57 |
| - int[] array = Enumerable.Range(1, 10000).ToArray(); |
58 |
| - |
59 |
| - public IterateBenchmark() |
60 |
| - { |
61 |
| - |
62 |
| - } |
63 |
| - |
64 |
| - [Benchmark] |
65 |
| - public void SystemLinq() |
66 |
| - { |
67 |
| - var seq = array |
68 |
| - .Select(x => x * 3) |
69 |
| - .Where(x => x % 2 == 0); |
70 |
| - |
71 |
| - foreach (var item in seq) |
72 |
| - { |
73 |
| - } |
74 |
| - } |
75 |
| - |
76 |
| - [Benchmark] |
77 |
| - public void ZLinq() |
78 |
| - { |
79 |
| - var seq = array.AsValueEnumerable() |
80 |
| - .Select(x => x * 3) |
81 |
| - .Where(x => x % 2 == 0); |
82 |
| - |
83 |
| - foreach (var item in seq) { } |
84 |
| - } |
85 |
| - |
86 |
| - //[Benchmark] |
87 |
| - //public void ZLinqSpan() |
88 |
| - //{ |
89 |
| - // var seq = array.AsSpan().AsValueEnumerable() |
90 |
| - // .Select<SpanValueEnumerable<int>, int, int>(x => x * 3) |
91 |
| - // .Where<SelectValueEnumerable<SpanValueEnumerable<int>, int, int>, int>(x => x % 2 == 0); |
92 |
| - |
93 |
| - // foreach (var item in seq) |
94 |
| - // { |
95 |
| - |
96 |
| - // } |
97 |
| - //} |
98 |
| - |
99 |
| - [Benchmark] |
100 |
| - public void LinqGen() |
101 |
| - { |
102 |
| - var seq = array.Gen() |
103 |
| - .Select(x => x * 3) |
104 |
| - .Where(x => x % 2 == 0); |
105 |
| - |
106 |
| - foreach (var item in seq) |
107 |
| - { |
108 |
| - |
109 |
| - } |
110 |
| - } |
111 |
| - |
112 |
| - [Benchmark] |
113 |
| - public void LinqAf() |
| 14 | + public static int Main(string[] args) |
114 | 15 | {
|
115 |
| - var seq = LinqAF.ArrayExtensionMethods |
116 |
| - .Select(array, x => x * 3) |
117 |
| - .Where(x => x % 2 == 0); |
| 16 | +#if DEBUG |
| 17 | + BenchmarkRunner.Run<IterateBenchmark>(DefaultConfig.Instance.WithSummaryStyle(SummaryStyle.Default.WithTimeUnit(TimeUnit.Millisecond)), args); |
118 | 18 |
|
119 |
| - foreach (var item in seq) |
| 19 | + var i = 0; |
| 20 | + foreach (var item in typeof(Enumerable).GetMethods().GroupBy(x => x.Name)) |
120 | 21 | {
|
121 |
| - |
| 22 | + Console.WriteLine($"- [ ] {item.Key}"); |
| 23 | + i++; |
122 | 24 | }
|
123 |
| - } |
124 |
| - |
125 |
| - //[Benchmark] |
126 |
| - //public void StructLinq() |
127 |
| - //{ |
128 |
| - // var seq = array.ToValueEnumerable() |
129 |
| - // .Select(x => x * 3, x => x) |
130 |
| - // .Where(x => x % 2 == 0, x => x); |
131 |
| - |
132 |
| - // foreach (var item in seq) |
133 |
| - // { |
134 |
| - |
135 |
| - // } |
136 |
| - //} |
| 25 | + Console.WriteLine(i); |
| 26 | + return 0; |
| 27 | +#endif |
137 | 28 |
|
138 |
| - [Benchmark] |
139 |
| - public void SpanLinq() |
140 |
| - { |
141 |
| - var seq = array.AsSpan() |
142 |
| - .Select(x => x * 3) |
143 |
| - .Where(x => x % 2 == 0); |
| 29 | + if (args != null && args.Length != 0) |
| 30 | + Console.WriteLine($"Start ZLinq benchmarks with args: {string.Join(' ', args)}"); |
144 | 31 |
|
145 |
| - foreach (var item in seq) |
146 |
| - { |
| 32 | + var switcher = BenchmarkSwitcher.FromAssemblies([typeof(Program).Assembly]); |
| 33 | + switcher.Run(args).ToArray(); |
147 | 34 |
|
148 |
| - } |
| 35 | + return 0; |
149 | 36 | }
|
150 | 37 | }
|
0 commit comments