-Perf tests

This commit is contained in:
James Newton-King
2017-01-09 23:44:08 +13:00
parent c9b2ec8055
commit 5fefa723ad
2 changed files with 60 additions and 1 deletions
+8 -1
View File
@@ -53,7 +53,7 @@ namespace Newtonsoft.Json.TestConsole
//t.DeserializeLargeJson(); //t.DeserializeLargeJson();
//PerformanceTests t = new PerformanceTests(); //PerformanceTests t = new PerformanceTests();
SerializeJsonAsync(); TokenWriteToAsync();
//t.Iterations = 50000; //t.Iterations = 50000;
//t.BenchmarkDeserializeMethod<TestClass>(PerformanceTests.SerializeMethod.JsonNet, PerformanceTests.JsonText); //t.BenchmarkDeserializeMethod<TestClass>(PerformanceTests.SerializeMethod.JsonNet, PerformanceTests.JsonText);
@@ -96,6 +96,13 @@ namespace Newtonsoft.Json.TestConsole
} }
} }
public static void TokenWriteToAsync()
{
PerformanceTests t = new PerformanceTests();
t.Iterations = 50000;
t.TokenWriteToAsync().Wait();
}
public static void SerializeJsonAsync() public static void SerializeJsonAsync()
{ {
PerformanceTests t = new PerformanceTests(); PerformanceTests t = new PerformanceTests();
@@ -146,6 +146,40 @@ namespace Newtonsoft.Json.Tests
await BenchmarkSerializeMethodAsync(SerializeMethod.JsonNetManualAsync, test); await BenchmarkSerializeMethodAsync(SerializeMethod.JsonNetManualAsync, test);
} }
[Test]
public void TokenWriteTo()
{
JObject o = JObject.Parse(JsonText);
TimeOperation<JObject>(() =>
{
for (int i = 0; i < Iterations; i++)
{
StringWriter sw = new StringWriter();
o.WriteTo(new JsonTextWriter(sw));
}
return o;
}, "TokenWriteTo");
}
[Test]
public async Task TokenWriteToAsync()
{
JObject o = JObject.Parse(JsonText);
await TimeOperationAsync<JObject>(async () =>
{
for (int i = 0; i < Iterations; i++)
{
StringWriter sw = new StringWriter();
await o.WriteToAsync(new JsonTextWriter(sw));
}
return o;
}, "TokenWriteTo");
}
[Test] [Test]
public void ReadLargeJson() public void ReadLargeJson()
{ {
@@ -326,6 +360,24 @@ namespace Newtonsoft.Json.Tests
return result; return result;
} }
private async Task<T> TimeOperationAsync<T>(Func<Task<T>> operation, string name)
{
// warm up
await operation();
Stopwatch timed = new Stopwatch();
timed.Start();
T result = await operation();
Console.WriteLine(name);
Console.WriteLine("{0} ms", timed.ElapsedMilliseconds);
timed.Stop();
return result;
}
[Test] [Test]
public void LargeArrayJTokenPathPerformance() public void LargeArrayJTokenPathPerformance()
{ {