-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathOpenFeatureClientBenchmarks.cs
106 lines (87 loc) · 5.66 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
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 _domain;
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();
this._domain = fixture.Create<string>();
this._clientVersion = fixture.Create<string>();
this._flagName = fixture.Create<string>();
this._defaultBoolValue = fixture.Create<bool>();
this._defaultStringValue = fixture.Create<string>();
this._defaultIntegerValue = fixture.Create<int>();
this._defaultDoubleValue = fixture.Create<double>();
this._defaultStructureValue = fixture.Create<Value>();
this._emptyFlagOptions = new FlagEvaluationOptions(ImmutableList<Hook>.Empty, ImmutableDictionary<string, object>.Empty);
this._client = Api.Instance.GetClient(this._domain, this._clientVersion);
}
[Benchmark]
public async Task OpenFeatureClient_GetBooleanValue_WithoutEvaluationContext_WithoutFlagEvaluationOptions() =>
await this._client.GetBooleanValueAsync(this._flagName, this._defaultBoolValue);
[Benchmark]
public async Task OpenFeatureClient_GetBooleanValue_WithEmptyEvaluationContext_WithoutFlagEvaluationOptions() =>
await this._client.GetBooleanValueAsync(this._flagName, this._defaultBoolValue, EvaluationContext.Empty);
[Benchmark]
public async Task OpenFeatureClient_GetBooleanValue_WithEmptyEvaluationContext_WithEmptyFlagEvaluationOptions() =>
await this._client.GetBooleanValueAsync(this._flagName, this._defaultBoolValue, EvaluationContext.Empty, this._emptyFlagOptions);
[Benchmark]
public async Task OpenFeatureClient_GetStringValue_WithoutEvaluationContext_WithoutFlagEvaluationOptions() =>
await this._client.GetStringValueAsync(this._flagName, this._defaultStringValue);
[Benchmark]
public async Task OpenFeatureClient_GetStringValue_WithEmptyEvaluationContext_WithoutFlagEvaluationOptions() =>
await this._client.GetStringValueAsync(this._flagName, this._defaultStringValue, EvaluationContext.Empty);
[Benchmark]
public async Task OpenFeatureClient_GetStringValue_WithoutEvaluationContext_WithEmptyFlagEvaluationOptions() =>
await this._client.GetStringValueAsync(this._flagName, this._defaultStringValue, EvaluationContext.Empty, this._emptyFlagOptions);
[Benchmark]
public async Task OpenFeatureClient_GetIntegerValue_WithoutEvaluationContext_WithoutFlagEvaluationOptions() =>
await this._client.GetIntegerValueAsync(this._flagName, this._defaultIntegerValue);
[Benchmark]
public async Task OpenFeatureClient_GetIntegerValue_WithEmptyEvaluationContext_WithoutFlagEvaluationOptions() =>
await this._client.GetIntegerValueAsync(this._flagName, this._defaultIntegerValue, EvaluationContext.Empty);
[Benchmark]
public async Task OpenFeatureClient_GetIntegerValue_WithEmptyEvaluationContext_WithEmptyFlagEvaluationOptions() =>
await this._client.GetIntegerValueAsync(this._flagName, this._defaultIntegerValue, EvaluationContext.Empty, this._emptyFlagOptions);
[Benchmark]
public async Task OpenFeatureClient_GetDoubleValue_WithoutEvaluationContext_WithoutFlagEvaluationOptions() =>
await this._client.GetDoubleValueAsync(this._flagName, this._defaultDoubleValue);
[Benchmark]
public async Task OpenFeatureClient_GetDoubleValue_WithEmptyEvaluationContext_WithoutFlagEvaluationOptions() =>
await this._client.GetDoubleValueAsync(this._flagName, this._defaultDoubleValue, EvaluationContext.Empty);
[Benchmark]
public async Task OpenFeatureClient_GetDoubleValue_WithEmptyEvaluationContext_WithEmptyFlagEvaluationOptions() =>
await this._client.GetDoubleValueAsync(this._flagName, this._defaultDoubleValue, EvaluationContext.Empty, this._emptyFlagOptions);
[Benchmark]
public async Task OpenFeatureClient_GetObjectValue_WithoutEvaluationContext_WithoutFlagEvaluationOptions() =>
await this._client.GetObjectValueAsync(this._flagName, this._defaultStructureValue);
[Benchmark]
public async Task OpenFeatureClient_GetObjectValue_WithEmptyEvaluationContext_WithoutFlagEvaluationOptions() =>
await this._client.GetObjectValueAsync(this._flagName, this._defaultStructureValue, EvaluationContext.Empty);
[Benchmark]
public async Task OpenFeatureClient_GetObjectValue_WithEmptyEvaluationContext_WithEmptyFlagEvaluationOptions() =>
await this._client.GetObjectValueAsync(this._flagName, this._defaultStructureValue, EvaluationContext.Empty, this._emptyFlagOptions);
}
}