-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathOpenFeatureClientBenchmarks.cs
107 lines (88 loc) · 5.36 KB
/
OpenFeatureClientBenchmarks.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
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using AutoFixture;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using OpenFeature.Model;
namespace OpenFeature.Benchmark
{
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net60, baseline: true)]
[JsonExporterAttribute.Full]
[JsonExporterAttribute.FullCompressed]
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task")]
public class OpenFeatureClientBenchmarks
{
private readonly string _clientName;
private readonly string _clientVersion;
private readonly string _flagName;
private readonly bool _defaultBoolValue;
private readonly string _defaultStringValue;
private readonly int _defaultIntegerValue;
private readonly double _defaultDoubleValue;
private readonly Value _defaultStructureValue;
private readonly FlagEvaluationOptions _emptyFlagOptions;
private readonly FeatureClient _client;
public OpenFeatureClientBenchmarks()
{
var fixture = new Fixture();
_clientName = fixture.Create<string>();
_clientVersion = fixture.Create<string>();
_flagName = fixture.Create<string>();
_defaultBoolValue = fixture.Create<bool>();
_defaultStringValue = fixture.Create<string>();
_defaultIntegerValue = fixture.Create<int>();
_defaultDoubleValue = fixture.Create<double>();
_defaultStructureValue = fixture.Create<Value>();
_emptyFlagOptions = new FlagEvaluationOptions(ImmutableList<Hook>.Empty, ImmutableDictionary<string, object>.Empty);
Api.Instance.SetProvider(new NoOpFeatureProvider());
_client = Api.Instance.GetClient(_clientName, _clientVersion);
}
[Benchmark]
public async Task OpenFeatureClient_GetBooleanValue_WithoutEvaluationContext_WithoutFlagEvaluationOptions() =>
await _client.GetBooleanValue(_flagName, _defaultBoolValue);
[Benchmark]
public async Task OpenFeatureClient_GetBooleanValue_WithEmptyEvaluationContext_WithoutFlagEvaluationOptions() =>
await _client.GetBooleanValue(_flagName, _defaultBoolValue, EvaluationContext.Empty);
[Benchmark]
public async Task OpenFeatureClient_GetBooleanValue_WithEmptyEvaluationContext_WithEmptyFlagEvaluationOptions() =>
await _client.GetBooleanValue(_flagName, _defaultBoolValue, EvaluationContext.Empty, _emptyFlagOptions);
[Benchmark]
public async Task OpenFeatureClient_GetStringValue_WithoutEvaluationContext_WithoutFlagEvaluationOptions() =>
await _client.GetStringValue(_flagName, _defaultStringValue);
[Benchmark]
public async Task OpenFeatureClient_GetStringValue_WithEmptyEvaluationContext_WithoutFlagEvaluationOptions() =>
await _client.GetStringValue(_flagName, _defaultStringValue, EvaluationContext.Empty);
[Benchmark]
public async Task OpenFeatureClient_GetStringValue_WithoutEvaluationContext_WithEmptyFlagEvaluationOptions() =>
await _client.GetStringValue(_flagName, _defaultStringValue, EvaluationContext.Empty, _emptyFlagOptions);
[Benchmark]
public async Task OpenFeatureClient_GetIntegerValue_WithoutEvaluationContext_WithoutFlagEvaluationOptions() =>
await _client.GetIntegerValue(_flagName, _defaultIntegerValue);
[Benchmark]
public async Task OpenFeatureClient_GetIntegerValue_WithEmptyEvaluationContext_WithoutFlagEvaluationOptions() =>
await _client.GetIntegerValue(_flagName, _defaultIntegerValue, EvaluationContext.Empty);
[Benchmark]
public async Task OpenFeatureClient_GetIntegerValue_WithEmptyEvaluationContext_WithEmptyFlagEvaluationOptions() =>
await _client.GetIntegerValue(_flagName, _defaultIntegerValue, EvaluationContext.Empty, _emptyFlagOptions);
[Benchmark]
public async Task OpenFeatureClient_GetDoubleValue_WithoutEvaluationContext_WithoutFlagEvaluationOptions() =>
await _client.GetDoubleValue(_flagName, _defaultDoubleValue);
[Benchmark]
public async Task OpenFeatureClient_GetDoubleValue_WithEmptyEvaluationContext_WithoutFlagEvaluationOptions() =>
await _client.GetDoubleValue(_flagName, _defaultDoubleValue, EvaluationContext.Empty);
[Benchmark]
public async Task OpenFeatureClient_GetDoubleValue_WithEmptyEvaluationContext_WithEmptyFlagEvaluationOptions() =>
await _client.GetDoubleValue(_flagName, _defaultDoubleValue, EvaluationContext.Empty, _emptyFlagOptions);
[Benchmark]
public async Task OpenFeatureClient_GetObjectValue_WithoutEvaluationContext_WithoutFlagEvaluationOptions() =>
await _client.GetObjectValue(_flagName, _defaultStructureValue);
[Benchmark]
public async Task OpenFeatureClient_GetObjectValue_WithEmptyEvaluationContext_WithoutFlagEvaluationOptions() =>
await _client.GetObjectValue(_flagName, _defaultStructureValue, EvaluationContext.Empty);
[Benchmark]
public async Task OpenFeatureClient_GetObjectValue_WithEmptyEvaluationContext_WithEmptyFlagEvaluationOptions() =>
await _client.GetObjectValue(_flagName, _defaultStructureValue, EvaluationContext.Empty, _emptyFlagOptions);
}
}