en	= 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:

en	Name

en	Description

en	*boost(pool)*

en	Parses the input using a <<ref_monotonic_resource>>,

en	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.

en	*boost*

en	Parses the input using the <<default_memory_resource, default memory

en	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.

en	*rapidjson(pool)*

en	Parses the input using an instance of

en	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.

en	*rapidjson*

en	Parses the input using an instance of

en	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.

en	*nlohmann*

en	Parses the input using the static member function

en	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. |===

en	Methodology

en	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.

en	The input files, available in the bench/data directory, are laid out thusly:

en	Name

en	Size

en	Description

en	<<parse_apache_builds_json,*apache_builds.json*>>

en	125KB

en	Data from the Apache Jenkins installation.

en	<<parse_canada_json,*canada.json*>>

en	2.2MB

en	The largest file, containing a large number of 2-element arrays holding

en	floating-point coordinate pairs.

en	<<parse_citm_catalog_json,*citm_catalog.json*>>

en	1.69MB

en	A large JSON with a variety of nesting, types, and lengths.

en	<<parse_github_events_json,*github_events.json*>>

en	64KB

en	An export of data from the Github Events API.

en	<<parse_gsoc_2018_json,*gsoc-2018.json*>>

en	3.25MB

en	Google Summer of Code 2018 data.

en	<<parse_instruments_json,*instruments.json*>>

en	216KB

en	An array of large objects.

en	<<parse_marine_ik_json,*marine_ik.json*>>

en	2.91MB

en	A three.js example model serialized to JSON.

en	<<parse_mesh_json,*mesh.json*>>

en	707KB

en	A JSON representing a 3D mesh. Contains many floating-point numbers.

en	<<parse_mesh_pretty_json,*mesh.pretty.json*>>

en	1.54MB

en	mesh.json with whitespace added.

en	<<parse_numbers_json,*numbers.json*>>

en	147KB

en	A array containing only floating-point numbers.

en	<<parse_random_json,*random.json*>>

en	499KB

en	A JSON with lots of Cyrillic characters.

en	<<parse_twitter_json,*twitter.json*>>

en	617KB

en	An export of data from Twitter's API.

en	<<parse_twitterescaped_json,*twitterescaped.json*>>

en	550KB

en	twitter.json with whitespace removed and non-ASCII characters replaced with

en	Unicode escapes.

en	<<parse_update_center_json,*update-center.json*>>

en	521KB

en	An export of data from Twitter's API.

en	Hardware used for testing: **Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz**, Windows 10, 32GB RAM.

en	Compilers and optimization flags: gcc 8.1 (-O3), clang 12.0 (-O3), and msvc 19.26 (/O2).

en	Parsing

en	Parse apache_builds.json

en	image::images/parse_apache_builds.png[width=668,align="left"]

en	Parse canada.json

en	image::images/parse_canada.png[width=668,align="left"]

en	Parse citm_catalog.json

en	image::images/parse_citm_catalog.png[width=668,align="left"]

en	Parse github_events.json

en	image::images/parse_github_events.png[width=668,align="left"]

en	Parse gsoc-2018.json

en	image::images/parse_gsoc_2018.png[width=668,align="left"]

en	Parse instruments.json

en	image::images/parse_instruments.png[width=668,align="left"]

en	Parse marine_ik.json

en	image::images/parse_marine_ik.png[width=668,align="left"]

en	Parse mesh.json

en	image::images/parse_mesh.png[width=668,align="left"]

en	Parse mesh.pretty.json

en	image::images/parse_mesh_pretty.png[width=668,align="left"]

en	Parse numbers.json

en	image::images/parse_numbers.png[width=668,align="left"]

en	Parse random.json

en	image::images/parse_random.png[width=668,align="left"]

en	Parse twitter.json

en	image::images/parse_twitter.png[width=668,align="left"]

en	Parse twitterescaped.json

en	image::images/parse_twitterescaped.png[width=668,align="left"]

en	Parse update-center.json

en	image::images/parse_update_center.png[width=668,align="left"]

en	Serialization

en	Serialize canada.json

en	image::images/serialize_canada.png[width=668,align="left"]

en	Serialize citm_catalog.json

en	image::images/serialize_citm_catalog.png[width=668,align="left"]

en	Serialize github_events.json

en	image::images/serialize_github_events.png[width=668,align="left"]

en	Serialize gsoc-2018.json

en	image::images/serialize_gsoc_2018.png[width=668,align="left"]

en	Serialize instruments.json

en	image::images/serialize_instruments.png[width=668,align="left"]

en	Serialize marine_ik.json

en	image::images/serialize_marine_ik.png[width=668,align="left"]

en	Serialize mesh.json

en	image::images/serialize_mesh.png[width=668,align="left"]

en	Serialize mesh.pretty.json

en	image::images/serialize_mesh_pretty.png[width=668,align="left"]

en	Serialize numbers.json

en	image::images/serialize_numbers.png[width=668,align="left"]

en	Serialize random.json

en	image::images/serialize_random.png[width=668,align="left"]

en	Serialize twitter.json

en	image::images/serialize_twitter.png[width=668,align="left"]

en	Serialize twitterescaped.json

en	image::images/serialize_twitterescaped.png[width=668,align="left"]

en	Serialize update-center.json

en	image::images/serialize_update_center.png[width=668,align="left"]