-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathIntroPercentiles.cs
More file actions
57 lines (51 loc) · 1.63 KB
/
IntroPercentiles.cs
File metadata and controls
57 lines (51 loc) · 1.63 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
48
49
50
51
52
53
54
55
56
57
using System;
using System.Threading;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Engines;
namespace BenchmarkDotNet.Samples
{
// Using percentiles for adequate timings representation
[Config(typeof(Config))]
[UseLocalJobOnly]
[SimpleJob(RunStrategy.ColdStart, launchCount: 4,
warmupCount: 3, iterationCount: 20, id: "MyJob")]
public class IntroPercentiles
{
// To share between runs.
// DO NOT do this in production code. The System.Random IS NOT thread safe.
private static readonly Random Rnd = new Random();
private class Config : ManualConfig
{
public Config()
{
AddColumn(
StatisticColumn.P0,
StatisticColumn.P25,
StatisticColumn.P50,
StatisticColumn.P67,
StatisticColumn.P80,
StatisticColumn.P85,
StatisticColumn.P90,
StatisticColumn.P95,
StatisticColumn.P100);
}
}
[Benchmark(Baseline = true)]
public void ConstantDelays() => Thread.Sleep(20);
[Benchmark]
public void RandomDelays() => Thread.Sleep(10 + (int) (20 * Rnd.NextDouble()));
[Benchmark]
public void RareDelays()
{
int rndTime = 10;
// Bigger delays for 15% of the runs
if (Rnd.NextDouble() > 0.85)
{
rndTime += 30;
}
Thread.Sleep(rndTime);
}
}
}