-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JsonNode construction benchmarks
- Loading branch information
1 parent
254b737
commit 7165eda
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/benchmarks/micro/libraries/System.Text.Json/Node/Perf_Create.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} | ||
} | ||
} |