-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathIntroDisassemblyRyuJit.cs
More file actions
35 lines (29 loc) · 791 Bytes
/
IntroDisassemblyRyuJit.cs
File metadata and controls
35 lines (29 loc) · 791 Bytes
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
using System.Linq;
using BenchmarkDotNet.Attributes;
namespace BenchmarkDotNet.Samples
{
[DisassemblyDiagnoser(printSource: true)]
[RyuJitX64Job]
[UseLocalJobOnly]
public class IntroDisassemblyRyuJit
{
private int[] field = Enumerable.Range(0, 100).ToArray();
[Benchmark]
public int SumLocal()
{
var local = field; // we use local variable that points to the field
int sum = 0;
for (int i = 0; i < local.Length; i++)
sum += local[i];
return sum;
}
[Benchmark]
public int SumField()
{
int sum = 0;
for (int i = 0; i < field.Length; i++)
sum += field[i];
return sum;
}
}
}