-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathIntroMemoryRandomization.cs
More file actions
31 lines (26 loc) · 873 Bytes
/
IntroMemoryRandomization.cs
File metadata and controls
31 lines (26 loc) · 873 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
using BenchmarkDotNet.Attributes;
using System;
namespace BenchmarkDotNet.Samples
{
[UseLocalJobOnly]
public class IntroMemoryRandomization
{
[Params(512 * 4)]
public int Size;
private int[] array = default!;
private int[] destination = default!;
[GlobalSetup]
public void Setup()
{
array = new int[Size];
destination = new int[Size];
}
[Benchmark]
[MemoryRandomization(false)]
public void Array_RandomizationDisabled() => Array.Copy(array, destination, Size);
[Benchmark]
[MemoryRandomization(true)]
[MaxIterationCount(40)] // the benchmark becomes multimodal and need a lower limit of max iterations than the default
public void Array_RandomizationEnabled() => Array.Copy(array, destination, Size);
}
}