-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathProgram.cs
More file actions
75 lines (58 loc) · 1.52 KB
/
Copy pathProgram.cs
File metadata and controls
75 lines (58 loc) · 1.52 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
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<LinqMinMaxBenchmarks>();
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net10_0, baseline: true)]
[SimpleJob(RuntimeMoniker.Net11_0)]
public class LinqMinMaxBenchmarks
{
private byte[] _bytes = null!;
private short[] _shorts = null!;
private int[] _ints = null!;
private long[] _longs = null!;
[Params(16, 64, 1_024)]
public int Length { get; set; }
[GlobalSetup]
public void Setup()
{
var random = new Random(42);
_bytes = new byte[Length];
_shorts = new short[Length];
_ints = new int[Length];
_longs = new long[Length];
random.NextBytes(_bytes);
for (var i = 0; i < Length; i++)
{
_shorts[i] = (short)random.Next(
short.MinValue,
short.MaxValue);
_ints[i] = random.Next();
_longs[i] = random.NextInt64();
}
}
[Benchmark]
public byte MinByte()
=> _bytes.Min();
[Benchmark]
public byte MaxByte()
=> _bytes.Max();
[Benchmark]
public short MinShort()
=> _shorts.Min();
[Benchmark]
public short MaxShort()
=> _shorts.Max();
[Benchmark]
public int MinInt()
=> _ints.Min();
[Benchmark]
public int MaxInt()
=> _ints.Max();
[Benchmark]
public long MinLong()
=> _longs.Min();
[Benchmark]
public long MaxLong()
=> _longs.Max();
}