= Benchmarks This section compares the performance of Boost.JSON with two widely used libraries with similar functionality: RapidJSON which is known for its performance, and JSON for Modern C++ which is known for feature-richness. The bench program measures the throughput of parsing and serialization for the a set of JSON representing typical workloads. These implementations are evaluated:
which is optimized for parsing without subsequent modification. The <<ref_stream_parser>> object is reused between trials, allowing temporary memory allocated by the implementation to persist and improve performance.
resource>>, which uses the standard C++ allocator, and is designed for general use including mutation of the document after it is parsed. The <<ref_stream_parser>> object is reused between trials, allowing temporary memory allocated by the implementation to persist and improve performance.
https://rapidjson.org/classrapidjson_1_1_memory_pool_allocator.html[`MemoryPoolAllocator`], which is optimized for parsing without subsequent modification. The https://rapidjson.org/classrapidjson_1_1_generic_document.html[`Document`] object holding temporary memory is not reused between trials, otherwise memory consumption grows without bounds and invalidates the benchmark.
https://rapidjson.org/classrapidjson_1_1_crt_allocator.html[`CrtAllocator`], which uses the standard C++ allocator, and is designed for general use including mutation of the document after it is parsed. The https://rapidjson.org/classrapidjson_1_1_generic_document.html[`Document`] object holding temporary memory is not reused between trials, otherwise memory consumption grows without bounds and invalidates the benchmark.
https://nlohmann.github.io/json/classnlohmann_1_1basic__json_ab330c13ba254ea41fbc1c52c5c610f45.html[`json::parse`], which uses the default `std` allocator, and is designed for general use including mutation of the document after it is parsed. This library does not provide an interface to reuse temporary storage used during parsing or serialization on subsequent operations. |===
The input files are all loaded first. Then each configuration is run for a sufficient number of trials to last at least 5 seconds. The elapsed time, number of invocations (of parse or serialize), and bytes transferred are emitted as a sample along with a calculation of throughput expressed in megabytes per second. Several samples (currently five) are generated for each configuration. All but the median two samples are discarded, with the remaining samples averaged to produce a single number which is reported as the benchmark result.