Skip to content

EgorBot for PranavSenthilnathan in #111332 #231

Open
@EgorBot

Description

@EgorBot

Processing dotnet/runtime#111332 (comment) command:

Command

-amd -arm -profiler --envvars DOTNET_JitDisasm:System.Text.Json.JsonDocument:WriteString(byref,System.Text.Json.Utf8JsonWriter)

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

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

public class Perf_ParseThenWrite
{
    const string jsonString =
"""
{
    "tags": [
      "culpa",
    "laboris",
    "nulla",
    "exercitation",
    "do",
    "pariatur",
    "occaecat",
    "aliquip",
    "est",
    "et",
    "officia",
    "minim",
    "quis",
    "est",
    "ullamco",
    "consequat",
    "id",
    "esse",
    "irure",
    "reprehenderit",
    "proident",
    "labore",
    "et",
    "in",
    "consequat",
    "officia",
    "exercitation",
    "aute",
    "do",
    "consequat",
    "laborum",
    "officia",
    "consectetur",
    "deserunt",
    "ex",
    "do",
    "nostrud",
    "deserunt",
    "consectetur",
    "adipisicing",
    "et",
    "non",
    "veniam",
    "dolor",
    "Lorem",
    "sunt",
    "amet",
    "cillum",
    "excepteur",
    "mollit"
    ]
}
""";

    private byte[] _dataUtf8;
    private Utf8JsonWriter _writer;

    public bool IsDataIndented = true;

    [GlobalSetup]
    public void Setup()
    {
        _dataUtf8 = Encoding.UTF8.GetBytes(jsonString);

        var abw = new ArrayBufferWriter<byte>();
        _writer = new Utf8JsonWriter(abw, new JsonWriterOptions { Indented = IsDataIndented });
    }

    [GlobalCleanup]
    public void CleanUp()
    {
        _writer.Dispose();
    }

    [Benchmark]
    public void ParseThenWrite()
    {
        _writer.Reset();

        using (JsonDocument document = JsonDocument.Parse(_dataUtf8))
        {
            document.WriteTo(_writer);
        }
    }
}

(EgorBot will reply in this issue)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions