diff --git a/Src/Newtonsoft.Json.TestConsole/Program.cs b/Src/Newtonsoft.Json.TestConsole/Program.cs index a173489a..1bc7d46a 100644 --- a/Src/Newtonsoft.Json.TestConsole/Program.cs +++ b/Src/Newtonsoft.Json.TestConsole/Program.cs @@ -37,7 +37,7 @@ namespace Newtonsoft.Json.TestConsole string version = FileVersionInfo.GetVersionInfo(typeof(JsonConvert).Assembly.Location).FileVersion; Console.WriteLine("Json.NET Version: " + version); - new BenchmarkSwitcher(new [] { typeof(SerializeBenchmarks), typeof(DeserializeBenchmarks) }).Run(new[] { "*" }); + new BenchmarkSwitcher(new [] { typeof(LowLevelBenchmarks) }).Run(new[] { "*" }); } } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Benchmarks/LowLevelBenchmarks.cs b/Src/Newtonsoft.Json.Tests/Benchmarks/LowLevelBenchmarks.cs index 6cf7f7de..2adefc6d 100644 --- a/Src/Newtonsoft.Json.Tests/Benchmarks/LowLevelBenchmarks.cs +++ b/Src/Newtonsoft.Json.Tests/Benchmarks/LowLevelBenchmarks.cs @@ -26,6 +26,7 @@ #if HAVE_BENCHMARKS using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -42,6 +43,34 @@ namespace Newtonsoft.Json.Tests.Benchmarks private const string FloatText = "123.123"; private static readonly char[] FloatChars = FloatText.ToCharArray(); + private static readonly Dictionary NormalDictionary = new Dictionary(); + + private static readonly ConcurrentDictionary ConcurrentDictionary = new ConcurrentDictionary(); + + static LowLevelBenchmarks() + { + for (int i = 0; i < 10; i++) + { + string key = i.ToString(); + object value = new object(); + + NormalDictionary.Add(key, value); + ConcurrentDictionary.TryAdd(key, value); + } + } + + [Benchmark] + public void DictionaryGet() + { + NormalDictionary.TryGetValue("one", out object _); + } + + [Benchmark] + public void ConcurrentDictionaryGet() + { + ConcurrentDictionary.TryGetValue("one", out object _); + } + [Benchmark] public void DecimalTryParseString() {