Skip to content

Latest commit

 

History

History
234 lines (154 loc) · 11 KB

README.md

File metadata and controls

234 lines (154 loc) · 11 KB

← .NET Matrix · Open the interactive matrix →

JSON Serialization

System.Text.Json leads the current rating · 3 libraries · 14 scenarios

Rating

In every scenario the fastest library scores 100 points and the one allocating least scores 100 more; four times slower is half the points, and an unsupported scenario is worth nothing. Time and memory reach 1300 each here, so the maximum is 2600. See workflows/rating.md.

JSON Serialization rating

# Library Scenarios Time Memory Points Group wins
1 System.Text.Json 13/13 1163 1149 2312 gold in Advanced, gold in Basic, gold in Collections, gold in Stream, silver in Nested, silver in Prepare
2 ServiceStack.Text 12/13 1102 888 1990 gold in Nested, gold in Prepare, silver in Advanced, silver in Basic, silver in Collections, silver in Stream
3 Newtonsoft.Json 13/13 791 398 1189 bronze in Advanced, bronze in Basic, bronze in Collections, bronze in Nested, bronze in Prepare, bronze in Stream
How the points were earned — every scenario, with the measurements behind it

Each row is one scenario. Best is the lowest result among the rated libraries that completed it, and the points follow from the two figures beside them: 100 × √((best + step) / (result + step)), with a step of 1 ns for time and 24 B for memory. A dash means the library did not complete the scenario, and it scores nothing for it. Add the two Points columns over every scenario and you get the rating above. The same breakdown appears as a hint on any points value in the application.

1. System.Text.Json — 2312 of 2600

Scenario Time Best Points Memory Best Points
Serialize Simple Object 89.07 ns 89.07 ns 100 96 B 96 B 100
Deserialize Simple Object 124.25 ns 106.16 ns 92.5 64 B 64 B 100
Serialize Nested Object 207.47 ns 207.47 ns 100 504 B 504 B 100
Deserialize Nested Object 316.43 ns 280.7 ns 94.2 768 B 320 B 65.9
Serialize Collection 278.04 ns 278.04 ns 100 560 B 560 B 100
Deserialize Collection 470.5 ns 384.13 ns 90.4 800 B 472 B 77.6
Serialize Dictionary 101.01 ns 100.35 ns 99.7 88 B 88 B 100
Deserialize Dictionary 173.06 ns 125.55 ns 85.3 312 B 312 B 100
Enum Round Trip 161.96 ns 161.96 ns 100 88 B 88 B 100
Custom Converter Round Trip 166.19 ns 166.19 ns 100 120 B 120 B 100
Polymorphic Round Trip 1.14 μs 1.14 μs 100 1.32 KB 1.32 KB 100
UTF-8 Stream Round Trip 325.45 ns 325.45 ns 100 280 B 280 B 100
Prepare Serializer 11.57 μs 0 ns 0.93 7.45 KB 0 B 5.6

2. ServiceStack.Text — 1990 of 2600

Scenario Time Best Points Memory Best Points
Serialize Simple Object 147.46 ns 89.07 ns 77.9 336 B 96 B 57.7
Deserialize Simple Object 106.16 ns 106.16 ns 100 112 B 64 B 80.4
Serialize Nested Object 321.17 ns 207.47 ns 80.4 792 B 504 B 80.4
Deserialize Nested Object 280.7 ns 280.7 ns 100 320 B 320 B 100
Serialize Collection 442.03 ns 278.04 ns 79.4 1000 B 560 B 75.5
Deserialize Collection 384.13 ns 384.13 ns 100 472 B 472 B 100
Serialize Dictionary 100.35 ns 100.35 ns 100 288 B 88 B 59.9
Deserialize Dictionary 125.55 ns 125.55 ns 100 424 B 312 B 86.6
Enum Round Trip 175.41 ns 161.96 ns 96.1 336 B 88 B 55.8
Custom Converter Round Trip 181.02 ns 166.19 ns 95.8 392 B 120 B 58.8
Polymorphic Round Trip — 1.14 μs 0 — 1.32 KB 0
UTF-8 Stream Round Trip 617.02 ns 325.45 ns 72.7 2.8 KB 280 B 32.4
Prepare Serializer 0 ns 0 ns 100 0 B 0 B 100

3. Newtonsoft.Json — 1189 of 2600

Scenario Time Best Points Memory Best Points
Serialize Simple Object 200.42 ns 89.07 ns 66.9 1.41 KB 96 B 28.6
Deserialize Simple Object 311.51 ns 106.16 ns 58.6 2.61 KB 64 B 18.1
Serialize Nested Object 356.44 ns 207.47 ns 76.4 1.63 KB 504 B 55.9
Deserialize Nested Object 600.28 ns 280.7 ns 68.4 2.89 KB 320 B 34
Serialize Collection 487.07 ns 278.04 ns 75.6 1.83 KB 560 B 55.5
Deserialize Collection 958.75 ns 384.13 ns 63.3 2.99 KB 472 B 40.1
Serialize Dictionary 191.88 ns 100.35 ns 72.5 1.48 KB 88 B 27
Deserialize Dictionary 310.54 ns 125.55 ns 63.7 2.83 KB 312 B 33.9
Enum Round Trip 636.24 ns 161.96 ns 50.6 4.68 KB 88 B 15.2
Custom Converter Round Trip 564.08 ns 166.19 ns 54.4 4.68 KB 120 B 17.3
Polymorphic Round Trip 2.24 μs 1.14 μs 71.3 7.79 KB 1.32 KB 41.5
UTF-8 Stream Round Trip 689.92 ns 325.45 ns 68.7 4.13 KB 280 B 26.8
Prepare Serializer 25.87 μs 0 ns 0.622 11.57 KB 0 B 4.497

Benchmark overview

Basic

JSON Serialization Basic benchmark overview

More overview charts (5)

Nested

JSON Serialization Nested benchmark overview

Collections

JSON Serialization Collections benchmark overview

Advanced

JSON Serialization Advanced benchmark overview

Stream

JSON Serialization Stream benchmark overview

Prepare

JSON Serialization Prepare benchmark overview

Compared libraries (3)

Newtonsoft.Json logo Newtonsoft.Json 13.0.4
A mature JSON framework for .NET with configurable contracts, converters, and streaming readers and writers.
Compare →
ServiceStack.Text logo ServiceStack.Text 10.4.2
A high-performance text library with typed JSON, stream, collection, and type-specific serialization APIs.
Compare →
System.Text.Json logo System.Text.Json
The reflection-based and source-generated JSON serializer included with .NET.
Compare →

Benchmark scenarios (14)

01 · Serialize Simple Object

Serializes one scalar object to a compact JSON string.

JSON Serialization Serialize Simple Object benchmark

02 · Deserialize Simple Object

Deserializes one compact JSON object and validates every scalar member.

JSON Serialization Deserialize Simple Object benchmark

03 · Serialize Nested Object

Serializes an order, customer, and address object graph.

JSON Serialization Serialize Nested Object benchmark

04 · Deserialize Nested Object

Deserializes and materializes an order, customer, and address object graph.

JSON Serialization Deserialize Nested Object benchmark

05 · Serialize Collection

Serializes three ordered objects to a compact JSON array.

JSON Serialization Serialize Collection benchmark

06 · Deserialize Collection

Deserializes a compact JSON array to three ordered objects.

JSON Serialization Deserialize Collection benchmark

07 · Serialize Dictionary

Serializes three ordered string and integer entries to a JSON object.

JSON Serialization Serialize Dictionary benchmark

08 · Deserialize Dictionary

Deserializes a JSON object to three ordinal string and integer entries.

JSON Serialization Deserialize Dictionary benchmark

09 · Enum Round Trip

Serializes an enum as its string name and deserializes it back.

JSON Serialization Enum Round Trip benchmark

10 · Custom Converter Round Trip

Serializes a strongly typed identifier as a JSON string and deserializes it back.

JSON Serialization Custom Converter Round Trip benchmark

11 · Polymorphic Round Trip

Round-trips a base-type collection through safe cat and dog discriminators.

JSON Serialization Polymorphic Round Trip benchmark

12 · UTF-8 Stream Round Trip

Serializes a simple object to a new UTF-8 memory stream and deserializes it back.

JSON Serialization UTF-8 Stream Round Trip benchmark

13 · Source Generation Round Trip

Round-trips a simple object with compile-time generated JSON metadata.

Not rated: With this few rated entrants, the reference is a library's own result, not a result earned against a competitor, so the full 200 points would not reflect a win. (1 of 3 rated libraries support this.)

JSON Serialization Source Generation Round Trip benchmark

14 · Prepare Serializer

Creates fresh serializer settings and explicit type metadata without serializing data.

JSON Serialization Prepare Serializer benchmark