/
DefaultMetricContextRegistryBenchmark.cs
127 lines (105 loc) · 4.93 KB
/
DefaultMetricContextRegistryBenchmark.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// <copyright file="DefaultMetricContextRegistryBenchmark.cs" company="Allan Hardy">
// Copyright (c) Allan Hardy. All rights reserved.
// </copyright>
using App.Metrics.Apdex;
using App.Metrics.Counter;
using App.Metrics.Gauge;
using App.Metrics.Histogram;
using App.Metrics.Infrastructure;
using App.Metrics.Internal;
using App.Metrics.Meter;
using App.Metrics.ReservoirSampling;
using App.Metrics.ReservoirSampling.ExponentialDecay;
using App.Metrics.Tagging;
using App.Metrics.Timer;
using BenchmarkDotNet.Attributes;
namespace App.Metrics.Benchmarks.BenchmarkDotNetBenchmarks.Metrics
{
public class DefaultMetricContextRegistryBenchmark : DefaultBenchmarkBase
{
private static readonly IBuildApdexMetrics ApdexBuilder = new DefaultApdexBuilder(new DefaultSamplingReservoirProvider(() => new DefaultForwardDecayingReservoir()));
private static readonly ApdexOptions ApdexOptions = new ApdexOptions
{
Name = "apdex"
};
private static readonly IClock Clock = new StopwatchClock();
private static readonly IBuildCounterMetrics CounterBuilder = new DefaultCounterBuilder();
private static readonly CounterOptions CounterOptions = new CounterOptions
{
Name = "counter"
};
private static readonly IBuildGaugeMetrics GaugeBuilder = new DefaultGaugeBuilder();
private static readonly GaugeOptions GaugeOptions = new GaugeOptions
{
Name = "gauge"
};
private static readonly IBuildHistogramMetrics HistogramBuilder = new DefaultHistogramBuilder(new DefaultSamplingReservoirProvider(() => new DefaultForwardDecayingReservoir()));
private static readonly HistogramOptions HistogramOptions = new HistogramOptions
{
Name = "histogram"
};
private static readonly IBuildMeterMetrics MeterBuilder = new DefaultMeterBuilder();
private static readonly MeterOptions MeterOptions = new MeterOptions
{
Name = "meter"
};
private static readonly IBuildTimerMetrics TimerBuilder = new DefaultTimerBuilder(new DefaultSamplingReservoirProvider(() => new DefaultForwardDecayingReservoir()));
private static readonly TimerOptions TimerOptions = new TimerOptions
{
Name = "timer"
};
private DefaultMetricContextRegistry _registry;
[GlobalSetup]
public override void Setup()
{
var tags = new GlobalMetricTags
{
{ "key1", "value1" },
{ "key2", "value2" }
};
_registry = new DefaultMetricContextRegistry("context_label", tags);
}
[Benchmark]
public void ResolveApdexFromRegistry()
{
_registry.Apdex(
ApdexOptions,
() => ApdexBuilder.Build(ApdexOptions.ApdexTSeconds, ApdexOptions.AllowWarmup, Clock));
}
[Benchmark]
public void ResolveCounterFromRegistry()
{
_registry.Counter(
CounterOptions,
() => CounterBuilder.Build());
}
[Benchmark]
public void ResolveGaugeFromRegistry()
{
_registry.Gauge(
GaugeOptions,
() => GaugeBuilder.Build(() => 1.0));
}
[Benchmark]
public void ResolveHistogramFromRegistry()
{
_registry.Histogram(
HistogramOptions,
() => HistogramBuilder.Build(HistogramOptions.Reservoir));
}
[Benchmark]
public void ResolveMeterFromRegistry()
{
_registry.Meter(
MeterOptions,
() => MeterBuilder.Build(Clock));
}
[Benchmark]
public void ResolveTimerFromRegistry()
{
_registry.Timer(
TimerOptions,
() => TimerBuilder.Build(TimerOptions.Reservoir, Clock));
}
}
}