diff --git a/test/My.Extensions.Localization.Json.Benchmarks/JsonResourceManagerTests.cs b/test/My.Extensions.Localization.Json.Benchmarks/JsonResourceManagerTests.cs new file mode 100644 index 0000000..7eaa6c4 --- /dev/null +++ b/test/My.Extensions.Localization.Json.Benchmarks/JsonResourceManagerTests.cs @@ -0,0 +1,42 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Toolchains.CsProj; +using My.Extensions.Localization.Json.Internal; +using System.Globalization; + +namespace My.Extensions.Localization.Json.Benchmarks +{ + [Config(typeof(BenchmarkConfig))] + public class JsonResourceManagerTests + { + private static readonly JsonResourceManager _jsonResourceManager; + private static readonly CultureInfo _frenchCulture; + + static JsonResourceManagerTests() + { + _jsonResourceManager = new JsonResourceManager("Resources\\fr-FR.json"); + _frenchCulture = CultureInfo.GetCultureInfo("fr-FR"); + } + + [Benchmark] + public void EvaluateGetResourceSetWithoutCultureFallback() + => _jsonResourceManager.GetResourceSet(_frenchCulture, tryParents: false); + + [Benchmark] + public void EvaluateGetResourceSetWithCultureFallback() + => _jsonResourceManager.GetResourceSet(_frenchCulture, tryParents: true); + + private class BenchmarkConfig : ManualConfig + { + public BenchmarkConfig() + { + var baseJob = Job.MediumRun.WithToolchain(CsProjCoreToolchain.NetCoreApp80); + + AddJob(baseJob.WithNuGet("My.Extensions.Localization.Json", "3.0.0")); + AddJob(baseJob.WithNuGet("My.Extensions.Localization.Json", "3.1.0")); + AddJob(baseJob.WithNuGet("My.Extensions.Localization.Json", "3.2.0")); + } + } + } +}