-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
39 lines (34 loc) · 878 Bytes
/
Program.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
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
var summary = BenchmarkRunner.Run(typeof(Program).Assembly);
public class ABCDRetrieval
{
private static double[] ABCD() => new double[] { 1, 2, 3, 4 };
[Benchmark]
public double ListPattern()
{
var abcd = ABCD();
if (abcd is [var a, var b, var c, var d])
{
return a + b + c + d;
}
else
{
throw new Exception("Can't happen.");
}
}
[Benchmark]
public double ArrayAccess()
{
var abcd = ABCD();
var (a, b, c, d) = (abcd[0], abcd[1], abcd[2], abcd[3]);
return a + b + c + d;
}
[Benchmark]
public double ArrayAccessHighToLow()
{
var abcd = ABCD();
var (d, c, b, a) = (abcd[3], abcd[2], abcd[1], abcd[0]);
return a + b + c + d;
}
}