Copyright(c) 2014-2015 Milo Yip (miloyip@gmail.com)
This benchmark evaluates the conformance and performance of 28 open-source C/C++ JSON parser/generator libraries. Performance means speed, memory, and code size.
Performance should be concerned only if the results are correct. This benchmark also test the conformance of library towards the JSON standards (RFC7159, ECMA-404).
Performance of JSON parsing/generation may be critical for server-side applications, mobile/embedded systems, or any application that requires processing of large size or number of JSONs. Native (C/C++) libraries are important because they should provide the best possible performance, while other languages may create bindings of native libraries.
The results show that several performance measurements vary in large scale among libraries. For example, the parsing time can be over 100 times. These differences came from many factors, including design and implementation details. For example, memory allocation strategies, design of variant type for JSON, number-string conversions, etc.
This benchmark may be useful for optimizing existing libraries and developing new, high-performance libraries.
The original author (Milo Yip) of this benchmark is also the primary author of RapidJSON.
Although the development of benchmark is attempted to be as objective and fair as possible, every benchmarks have their drawbacks, and are limited to particular testing procedures, datasets and platforms. And also, this benchmark does not compare additional features that a library may support, or the user-friendliness of APIs, securities, cross-platform, etc. The author encourage users to benchmarks with their own data sets and platforms.
Benchmark | Description |
---|---|
Parse Validation | Use JSON_checker test suite to test whether the library can identify valid and invalid JSONs. (fail01.json is excluded as it is relaxed in RFC7159. fail18.json is excluded as depth of JSON is not specified.) |
Parse Double | 66 JSONs, each with a decimal value in an array, are parsed. The parsed double values are compared to the correct answer. |
Parse String | 9 JSONs, each with a string value in an array, are parsed. The parsed strings are compared to the correct answer. |
Roundtrip | 27 condensed JSONs are parsed and stringified. The results are compared to the original JSONs. |
Benchmark | Description |
---|---|
Parse | Parse in-memory JSON into DOM (tree structure). |
Stringify | Serialize DOM into condensed JSON in memory. |
Prettify | Serialize DOM into prettified (with indentation and new lines) JSON in memory. |
Statistics | Traverse DOM and count the number of JSON types, total length of string, and total numbers of elements/members in array/objects. |
Sax Round-trip | Parse in-memory JSON into events and use events to generate JSON in memory. |
Sax Statistics | Parse in-memory JSON into events and use events to conduct the statistics. |
Code size | Executable size in byte. (Currently only support jsonstat program, which calls "Parse" and "Staistics" to print out statistics of a JSON file. ) |
All benchmarks contain the following measurements:
Measurement | Description |
---|---|
Time | Duration in millisecond |
Memory | Memory consumption in bytes for the result data structure. |
MemoryPeak | Peak memory consumption in bytes throughout the parsing process. |
AllocCount | Number of memory allocation (including malloc , realloc() , new et al.) |
Currently 20 libraries are successfully benchmarked. They are listed in alphabetic order:
Library | Language | Version | Notes |
---|---|---|---|
ArduinoJson | C++ | v4.2-3 | |
CAJUN | C++ | 2.0.3 | |
Casablanca (C++ REST SDK) | C++11 | 2.5.0 | Need Boost on non-Windows platform. DOM strings must be UTF16 on Windows and UTF8 on non-Windows platform. Fail to roundtrip twitter.json . |
cJSON | C | 2013-08-19 | |
dropbox/json11 | C++11 | ||
FastJson | C++ | ||
gason | C++11 | ||
jansson | C | v2.7 | |
jeayeson | C++14 | ||
json-c | C | ||
jsoncons | C++11 | 0.97.1 | |
json-voorhees | C++ | v1.0.0 | |
json spirit | C++ | 4.08 | Need Boost |
Json Box | C++ | 0.6.1 | |
JsonCpp | C++ | 1.0.0 | |
JSON++ | C++ | ||
Jzon | C++ | v2-1 | |
nbsdx/SimpleJSON | C++11 | ||
Nlohmann/json | C++11 | ||
parson | C | ||
picojson | C++ | 1.3.0 | |
RapidJSON | C++ | v1.0.1 | There are four configurations: RapidJSON (default), RapidJSON_AutoUTF (transcoding any UTF JSON), RapidJSON_Insitu (insitu parsing) & RapidJSON_FullPrec (full precision number parsing) |
sajson | C++ | ||
SimpleJSON | C++ | ||
udp/json | C | 1.1.0 | Actually 2 libraries: udp/json-parser & udp/json-builder. |
ujson4c | C | ||
vincenthz/libjson | C | 0.8 | |
YAJL | C | 2.1.0 |
Libraries with Git repository are included as submodule in thirdparty
path. Other libraries are add as files in thirdparty
path.
All libraries are latest version on 25 Apr 2015. The exact commit of submodule can be navigated at here.
To measure the overheads of the benchmark process, a strdup
test is added for comparison. It simply allocate and copy the input string in Parse and Stringify benchmark.
Besides, some libraries was tried to integrated in this benchmark but failed:
Library | Issue |
---|---|
libjson | Unable to parse UTF-8 string |
lastjson | |
StiX Json |
All tested JSON data are in UTF-8.
JSON file | Size | Description |
---|---|---|
canada.json source |
2199KB | Contour of Canada border in GeoJSON format. Contains a lot of real numbers. |
citm_catalog.json source |
1737KB | A big benchmark file with indentation used in several Java JSON parser benchmarks. |
twitter.json |
632KB | Search "一" (character of "one" in Japanese and Chinese) in Twitter public time line for gathering some tweets with CJK characters. |
The benchmark program reads data/data.txt
which contains file names of JSON to be tested.
- Execute
git submodule update --init
to download all submodules (libraries). - Obtain premake4.
- Copy premake4 executable to
build/
path (or system path). - Run
premake.bat
orpremake.sh
inbuild/
- On Windows, build the solution at
build/vs2008/
or/vs2010/
. - On other platforms, run GNU
make -f benchmark.make config=release32 && make -f nativejson.make
(orrelease64
) atbuild/gmake/
- Optional: run
buuild/machine.sh
for UNIX or CYGWIN to use CPU info to generate prefix of result filename. - Run the
nativejson_release_...
executable is generated atbin/
- The results in CSV format will be written to
result/
. - Run GNU
make
inresult/
to generate results in HTML.
For simplicity, on Linux/OSX users can simply run make
at project root to run 4-10 above.
A collection of benchmarks results can be viewed HERE. Select "Benchmark" from the menu to check available benchmark configurations. The presentation is powered by Google Charts with interactivity.
The followings are some snapshots from the results of an iMac (Corei5-3330S@2.70GHz) with clang 6.1_1 64-bit.
This is the average score of 4 conformance benchmarks. Higher is better. Details.
This is the total duration of parsing 3 JSONs to DOM representation, sorted in ascending order. Lower is better. [Details](https://rawgit.com/miloyip/nativejson-benchmark/master/sample/performance_Corei5-3330S@2.70GHz_mac64_clang6.1.html#1. Parse)
This is the total memory after parsing 3 JSONs to DOM representation, sorted in ascending order. Lower is better. [Details](https://rawgit.com/miloyip/nativejson-benchmark/master/sample/performance_Corei5-3330S@2.70GHz_mac64_clang6.1.html#1. Parse)
This is the total duration of stringifying 3 DOMs to JSONs, sorted in ascending order. Lower is better. [Details](https://rawgit.com/miloyip/nativejson-benchmark/master/sample/performance_Corei5-3330S@2.70GHz_mac64_clang6.1.html#2. Stringify)
This is the total duration of prettifying 3 DOMs to JSONs, sorted in ascending order. Lower is better. [Details](https://rawgit.com/miloyip/nativejson-benchmark/master/sample/performance_Corei5-3330S@2.70GHz_mac64_clang6.1.html#2. Prettify)
The is the size of executable program, which parses a JSON from stdin
to a DOM and then computes the statistics of the DOM. Lower is better. [Details](https://rawgit.com/miloyip/nativejson-benchmark/master/sample/performance_Corei5-3330S@2.70GHz_mac64_clang6.1.html#7. Code size)
-
How to add a library?
Use
submodule add https://...xxx.git thirdparty/xxx
to add the libary's repository as a submobule. If that is not possible, just copy the files into 'thirdparty/xxx'.For C libary, add a
xxx_all.c
insrc/cjsonlibs
, which#include
all the necessary.c
files of the library. And then create atests/xxxtest.cpp
.For C++ library, just need to create a
tests/xxxtest.cpp
, which#include
all the necessary.cpp
files of the library.You may find a existing library which similar to your case as a start of implementing
tests/xxxtest.cpp
.
-
Basic benchmarks for miscellaneous C++ JSON parsers and generators by Mateusz Loskot (Jun 2013)
-
JSON Parser Benchmarking by Chad Austin (Jan 2013)
-
vjson (Replaced by gason)