Skip to content

Commit

Permalink
Add JsonNode construction benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriktsarpalis committed Sep 17, 2024
1 parent 254b737 commit 7165eda
Showing 1 changed file with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using BenchmarkDotNet.Attributes;
using MicroBenchmarks;
using System.Text.Json.Nodes;

namespace System.Text.Json.Node.Tests
{
[BenchmarkCategory(Categories.Libraries, Categories.JSON)]
public class Perf_Create
{
[Benchmark]
public JsonNode Create_JsonBool()
{
return true;
}

[Benchmark]
public JsonNode Create_JsonNumber()
{
return 42;
}

[Benchmark]
public JsonNode Create_JsonString()
{
return "Some string";
}

[Benchmark]
public JsonNode Create_JsonArray()
{
return new JsonArray { null, null, null, null };
}

[Benchmark]
public JsonNode Create_JsonObject_Small()
{
return new JsonObject
{
["prop0"] = null,
["prop1"] = null,
["prop2"] = null,
["prop3"] = null,
["prop4"] = null,
["prop5"] = null,
["prop6"] = null,
["prop7"] = null,
["prop8"] = null,
};
}

[Benchmark]
public JsonNode Create_JsonObject_Large()
{
return new JsonObject
{
["prop0"] = null,
["prop1"] = null,
["prop2"] = null,
["prop3"] = null,
["prop4"] = null,
["prop5"] = null,
["prop6"] = null,
["prop7"] = null,
["prop8"] = null,
["prop9"] = null,
["prop10"] = null,
["prop11"] = null,
["prop12"] = null,
["prop13"] = null,
["prop14"] = null,
["prop15"] = null,
["prop16"] = null,
["prop17"] = null,
["prop18"] = null,
["prop19"] = null,
};
}
}
}

0 comments on commit 7165eda

Please sign in to comment.