JSON is the ubiquitous data format on the Internet. There is a lot of JSON that needs to be parsed and validated.
As we just released the latest version of our fast JSON parser (simdjson), a reader of this blog asked how it compared in speed against one of the nicest C++ JSON libraries: JSON for Modern C++ (nlohmann/json).
We have not reported on benchmarks against “JSON for Modern C++” because we knew that it was not designed for raw speed. It is designed for ease-of-use: it makes the life of the programmer as easy as possible. In contrast, simdjson optimizes for speed, even when it requires a bit more work from the programmer. Nevertheless, it is still interesting to compare speed, to know what your trade-off is.
Let us run some benchmarks… I use a Skylake processor with GNU GCC 8.3.
file | simdjson | JSON for Modern C++ |
---|---|---|
apache_builds | 2.3 GB/s | 0.098 GB/s |
github_events | 2.5 GB/s | 0.093 GB/s |
gsoc-2018 | 3.3 GB/s | 0.091 GB/s |
2.2 GB/s | 0.094 GB/s |
Thus, roughly speaking, simdjson can parse, validate a JSON document and create a DOM tree, at a speed of about 2 GB/s. The easier-to-use “JSON for Modern C++” has a speed of about 0.1 GB/s, so about 20x slower. As a reference, we can easily read files from disk or the network at speeds higher than 2 GB/s.
Link: simdjson.
Thanks, for posting this.
That is well a mega difference, very impressive. I’m just using it [nlohmann/json] for some settings and some data from the web, so speed is not relevant, but if it got to be relevant for another application, I’d definitely look into simdjson.
vcpkg has simdjson in its repo (for those that did not know).
We are working toward releasing version 0.2 on vcpkg.
Daniel, you wrote “[JSON for Modern C++] is designed for ease-of-use: it makes the life of the programmer as easy as possible. In contrast, simdjson optimizes for speed, even when it requires a bit more work from the programmer.” As a programmer I never used simdjson, but have some experience with nlohmann/json and I’m wondering how difficult to use your library is.
We support a conventional DOM traversal as well as JSON pointers. Our DOM tree is immutable.
Please try it out!