-
Notifications
You must be signed in to change notification settings - Fork 274
/
Copy pathConfigurationBinderBenchmarks.cs
54 lines (46 loc) · 1.83 KB
/
ConfigurationBinderBenchmarks.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Filters;
using MicroBenchmarks;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
namespace Microsoft.Extensions.Configuration
{
[BenchmarkCategory(Categories.Libraries)]
public class ConfigurationBinderBenchmarks
{
[Params(8, 16, 32)]
public int ConfigurationProvidersCount { get; set; }
[Params(10, 20, 40)]
public int KeysCountPerProvider { get; set; }
private IConfiguration _configuration;
[GlobalSetup]
public void GlobalSetup()
{
var builder = new ConfigurationBuilder();
for (int i = 0; i < this.ConfigurationProvidersCount; i++)
{
var s = new MySettings
{
IdMapping = Enumerable.Range(0, this.KeysCountPerProvider).ToDictionary(j => $"{i}_{j}", j => $"{j}_{i}")
};
builder.AddJsonStream(new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(s))));
}
_configuration = builder.Build();
}
[Benchmark]
[AotFilter("Not supported.")] // System.NotSupportedException: This object cannot be invoked because no code was generated for it: 'System.Collections.Generic.IDictionary`2[System.String, System.String].Item'.
[MemoryRandomization]
public MySettings Get() => _configuration.Get<MySettings>();
public class MySettings
{
public Dictionary<string, string> IdMapping { get; set; }
}
}
}