Home

Awesome

.NET vs JVM JSON serialization

This is reference benchmark for the fastest JSON serialization libraries in .NET and JVM. It includes various other libraries to show difference between them for various scenarios.

Varieties of models are tested, from small simple objects, to very complex large objects; with different number of loops. Unlike most benchmarks which use static data for test, test data for this benchmark is created within the code.

Many libraries are unable to fully complete the benchmark, due to various reasons.

To give more interesting results, we'll also run tests on Mono to see how it compares to JVM/.NET.

Models

Testing assumptions

Libraries

Startup times

It's known issue that serialization libraries suffer from startup time, since they need to build and cache parsers for types. Let's see how much of an issue that is:

Small 1 (Message)

Startup times

As expected baked in serialization code has minimal startup time, since it was amortized at compile time. While this can be nullified on servers with longer startup, it can cause noticeable delays on mobile apps. Java seems to be doing exceptionally well on startup times.

Small model

Model with only a few simple properties. This test mostly shows the overhead of the library since there is only little serialization to do.

Small 1.000.000 (Message)

Small objects duration

Since there is large number of loops JVM optimization kicks-in so it's interesting to compare it to both smaller number of loops (100k) and larger number of loops (10M).

Non-trivial model

Non-trivial model should reflect most CRUD scenarios with documents. Serialization algorithms should show difference between libraries.

Standard 100.000 (Post)

Non-trivial objects duration

LOH issue in .NET prohibits advanced optimizations available on JVM (in a sense that developers are forced to deal with it, instead of focusing on algorithms).

Large model

Large model contains several advanced features, such as interface serialization, occasional byte[] serialization and deep nested objects. Large strings and other objects are used which cause 10x slower instance creation in .NET.

Large 500 (Book)

Large objects duration

Most libraries are unable to complete this bench (due to requirement for advanced features; Jackson gets some help through annotations).

Mono comparison (results for 2016/4)

Mono has improved significantly with v4.

Small 10.000.000 (Post)

.NET vs Mono

It's only twice as slow as .NET version.

Full results

2015/6

AMD Phenom(tm) II X4 955 Processor 3.20 GHz / 24GB RAM

.NET 4.5.1, Mono 4.0.1, JVM 1.7.76/1.8.31

Results for Windows. Results for Linux. .NET vs Mono comparison.

2016/4

AMD Phenom(tm) II X4 955 Processor 3.20 GHz / 24GB RAM

.NET 4.6.2, Mono 4.2.3, JVM 1.8.77

Results for Windows. Results for Linux. .NET vs Mono comparison.

2016/7

Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz / 16GB RAM

.NET 4.6.2, JVM 1.8.102

Results for Windows.

Reproducing results

Run GatherResults.exe or GatherResults.exe . 5

Individual tests can be run as:

If you are interested in changing the models, then you can:

If you want to test other libraries run benchmark without arguments to find out which libraries are available. For example to test Microsoft Bond run: JsonBenchmark.exe BondBinary Small Both 1000000.

To check if library is working correctly, use Check argument. Some libraries are reported to work incorrectly but still included in results (Service Stack serializes only 3 digits on DateTime, which causes incorrect comparison after deserialization, ...)

Conclusions