This commit is contained in:
James Newton-King
2017-06-18 00:00:10 +12:00
parent 59cd89a140
commit 91783ff319
2 changed files with 30 additions and 1 deletions
+1 -1
View File
@@ -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[] { "*" });
}
}
}
@@ -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<string, object> NormalDictionary = new Dictionary<string, object>();
private static readonly ConcurrentDictionary<string, object> ConcurrentDictionary = new ConcurrentDictionary<string, object>();
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()
{