Skip to content

Commit

Permalink
Add System.Text.Json to benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienros committed May 7, 2024
1 parent 9959b64 commit 4cdd5ba
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion test/Parlot.Benchmarks/JsonBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Parlot.Fluent;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Text.Json;

namespace Parlot.Benchmarks
{
Expand All @@ -24,7 +25,8 @@ public class JsonBench
private Parser<IJson> _compiled;
#nullable restore

private static JsonSerializerSettings _jsonSerializerSettings = new JsonSerializerSettings() { MaxDepth = 1024 };
private static JsonSerializerSettings _jsonSerializerSettings = new() { MaxDepth = 1024 };
private static JsonSerializerOptions _jsonSerializerOptions = new() { MaxDepth = 1024 };
private static readonly Random _random = new();

[GlobalSetup]
Expand Down Expand Up @@ -62,6 +64,12 @@ public JToken BigJson_Newtonsoft()
return JToken.Parse(_bigJson);
}

[Benchmark, BenchmarkCategory("Big")]
public JsonDocument BigJson_SystemTextJson()
{
return JsonDocument.Parse(_bigJson);
}

[Benchmark, BenchmarkCategory("Big")]
public IJson BigJson_Sprache()
{
Expand Down Expand Up @@ -98,6 +106,13 @@ public JToken LongJson_Newtonsoft()
return JToken.Parse(_longJson);
}


[Benchmark, BenchmarkCategory("Long")]
public JsonDocument LongJson_SystemTextJson()
{
return JsonDocument.Parse(_longJson);
}

[Benchmark, BenchmarkCategory("Long")]
public IJson LongJson_Sprache()
{
Expand Down Expand Up @@ -134,6 +149,12 @@ public JToken DeepJson_Newtonsoft()
return JsonConvert.DeserializeObject<JToken>(_deepJson, _jsonSerializerSettings);
}

[Benchmark, BenchmarkCategory("Deep")]
public JsonDocument DeepJson_SystemTextJson()
{
return JsonDocument.Parse(_deepJson);
}

[Benchmark, BenchmarkCategory("Deep")]
public IJson DeepJson_Sprache()
{
Expand Down

0 comments on commit 4cdd5ba

Please sign in to comment.