Last active
March 9, 2019 17:18
-
-
Save kshyju/8ee72dd3ab948ffd2f1e4e4d45ec9094 to your computer and use it in GitHub Desktop.
Benchmark for ConfigurationRoot get method change using for loop instead of Reverse method call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.Configuration.Memory; | |
namespace Microsoft.Extensions.Primitives.Performance | |
{ | |
public class ConfigurationBenchmark | |
{ | |
private IConfigurationRoot configurationRoot; | |
private IConfigurationRoot configurationRoot2; | |
[GlobalSetup] | |
public void Setup() | |
{ | |
// Arrange | |
var dic1 = new Dictionary<string, string>() | |
{ | |
{"Mem1:KeyInMem1", "ValueInMem1"} | |
}; | |
var dic2 = new Dictionary<string, string>() | |
{ | |
{"Mem2:KeyInMem2", "ValueInMem2"} | |
}; | |
var memConfigSrc1 = new MemoryConfigurationSource { InitialData = dic1 }; | |
var memConfigSrc2 = new MemoryConfigurationSource { InitialData = dic2 }; | |
var provider1 = new MemoryConfigurationProvider(memConfigSrc1); | |
var provider2 = new MemoryConfigurationProvider(memConfigSrc2); | |
configurationRoot = new ConfigurationRoot(new IConfigurationProvider[] { | |
provider1, provider2 | |
}); | |
configurationRoot2 = new ConfigurationRootNew(new IConfigurationProvider[] { | |
provider1, provider2 | |
}); | |
} | |
[Benchmark] | |
public string UsingReverse() | |
{ | |
return configurationRoot["Mem1:KeyInMem1"]; | |
} | |
[Benchmark] | |
public string UsingForLoop() | |
{ | |
return configurationRoot2["Mem1:KeyInMem1"]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment