-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathProgram.cs
81 lines (70 loc) · 2.02 KB
/
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
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
76
77
78
79
80
81
// Made by Benjamin Abt - https://github.com/BenjaminAbt
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<Benchmark>();
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net70)] // PGO enabled by default
[SimpleJob(RuntimeMoniker.Net80)]
[SimpleJob(RuntimeMoniker.Net90, baseline: true)]
[HideColumns(Column.Job)]
public class Benchmark
{
private string _sampleString = new('a', 1000);
private int _a = 1;
private int _b = 10;
private int rows = 100;
[Benchmark]
public int SmallStruct()
{
int sum = 0;
for (int i = 0; i < rows; i++)
{
SmallStruct test = new(_a, _b);
sum = sum + Calc(test);
}
return sum;
}
[Benchmark]
public int MediumStruct()
{
int sum = 0;
for (int i = 0; i < rows; i++)
{
MediumStruct test = new(_a, _b, _sampleString, _sampleString);
sum = sum + Calc(test);
}
return sum;
}
[Benchmark]
public int SmallClass()
{
int sum = 0;
for (int i = 0; i < rows; i++)
{
SmallClass test = new(_a, _b);
sum = sum + Calc(test);
}
return sum;
}
[Benchmark]
public int MediumClass()
{
int sum = 0;
for (int i = 0; i < rows; i++)
{
MediumClass test = new(_a, _b, _sampleString, _sampleString);
sum = sum + Calc(test);
}
return sum;
}
private int Calc(SmallStruct input) => input.A + input.B;
private int Calc(MediumStruct input) => input.A + input.B;
private int Calc(SmallClass input) => input.A + input.B;
private int Calc(MediumClass input) => input.A + input.B;
}
public readonly record struct SmallStruct(int A, int B);
public readonly record struct MediumStruct(int A, int B, string X, string Y);
public record class SmallClass(int A, int B);
public record class MediumClass(int A, int B, string X, string Y);