-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathIntroDotMemoryDiagnoser.cs
More file actions
47 lines (40 loc) · 1.09 KB
/
IntroDotMemoryDiagnoser.cs
File metadata and controls
47 lines (40 loc) · 1.09 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
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Diagnostics.dotMemory;
using System.Collections.Generic;
namespace BenchmarkDotNet.Samples
{
// Profile benchmarks via dotMemory SelfApi profiling for all jobs
[DotMemoryDiagnoser]
[SimpleJob] // external-process execution
[InProcess] // in-process execution
[UseLocalJobOnly]
public class IntroDotMemoryDiagnoser
{
[Params(1024)]
public int Size;
private byte[] dataArray = default!;
private IEnumerable<byte> dataEnumerable = default!;
[GlobalSetup]
public void Setup()
{
dataArray = new byte[Size];
dataEnumerable = dataArray;
}
[Benchmark]
public int IterateArray()
{
var count = 0;
foreach (var _ in dataArray)
count++;
return count;
}
[Benchmark]
public int IterateEnumerable()
{
var count = 0;
foreach (var _ in dataEnumerable)
count++;
return count;
}
}
}