KEMBAR78
Use Utf8JsonWriterCache in JsonNode.To{Json}String by stephentoub · Pull Request #92358 · dotnet/runtime · GitHub
Skip to content

Conversation

@stephentoub
Copy link
Member

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Text.Json;
using System.Text.Json.Nodes;

BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);

[HideColumns("Error", "StdDev", "Median", "RatioSD", "Job")]
[MemoryDiagnoser(false)]
public class Tests
{
    private JsonNode _json = JsonNode.Parse("""
        {
          "employees": [
              {
                "Jane": {
                  "age": 30,
                  "position": "developer"
                }
              },
              {
                "John": {
                  "age": 30,
                  "position": "designer"
                }
              }]
        }
        """);
    private JsonNode _value = JsonValue.Create(42);

    [Benchmark] public new string ToString() => _json.ToString();
    [Benchmark] public string ToJsonString() => _json.ToJsonString();
    [Benchmark] public JsonValueKind GetValueKind() => _value.GetValueKind();
}
Method Toolchain Mean Ratio Allocated Alloc Ratio
ToString \main\corerun.exe 596.4 ns 1.00 600 B 1.00
ToString \pr\corerun.exe 566.2 ns 0.95 448 B 0.75
ToJsonString \main\corerun.exe 486.9 ns 1.00 376 B 1.00
ToJsonString \pr\corerun.exe 471.9 ns 0.97 224 B 0.60
GetValueKind \main\corerun.exe 180.6 ns 1.00 296 B 1.00
GetValueKind \pr\corerun.exe 163.6 ns 0.91 144 B 0.49

@ghost
Copy link

ghost commented Sep 20, 2023

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Text.Json;
using System.Text.Json.Nodes;

BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);

[HideColumns("Error", "StdDev", "Median", "RatioSD", "Job")]
[MemoryDiagnoser(false)]
public class Tests
{
    private JsonNode _json = JsonNode.Parse("""
        {
          "employees": [
              {
                "Jane": {
                  "age": 30,
                  "position": "developer"
                }
              },
              {
                "John": {
                  "age": 30,
                  "position": "designer"
                }
              }]
        }
        """);
    private JsonNode _value = JsonValue.Create(42);

    [Benchmark] public new string ToString() => _json.ToString();
    [Benchmark] public string ToJsonString() => _json.ToJsonString();
    [Benchmark] public JsonValueKind GetValueKind() => _value.GetValueKind();
}
Method Toolchain Mean Ratio Allocated Alloc Ratio
ToString \main\corerun.exe 596.4 ns 1.00 600 B 1.00
ToString \pr\corerun.exe 566.2 ns 0.95 448 B 0.75
ToJsonString \main\corerun.exe 486.9 ns 1.00 376 B 1.00
ToJsonString \pr\corerun.exe 471.9 ns 0.97 224 B 0.60
GetValueKind \main\corerun.exe 180.6 ns 1.00 296 B 1.00
GetValueKind \pr\corerun.exe 163.6 ns 0.91 144 B 0.49
Author: stephentoub
Assignees: stephentoub
Labels:

area-System.Text.Json

Milestone: -

Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@stephentoub stephentoub merged commit 614d864 into dotnet:main Sep 20, 2023
@stephentoub stephentoub deleted the jsonnodetostring branch September 20, 2023 19:56
@ghost ghost locked as resolved and limited conversation to collaborators Oct 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants