-Perf tests
This commit is contained in:
@@ -146,6 +146,40 @@ namespace Newtonsoft.Json.Tests
|
||||
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]
|
||||
public void ReadLargeJson()
|
||||
{
|
||||
@@ -326,6 +360,24 @@ namespace Newtonsoft.Json.Tests
|
||||
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]
|
||||
public void LargeArrayJTokenPathPerformance()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user