Repository navigation
Add benchmarks for SAX parsing, value operations, JSON Pointer, and conversions - #5845
Merged
Merged
Conversation
nlohmann
force-pushed
the
benchmarks/value-operations
branch
3 times, most recently
from
October 20, 2026 05:51
c1824a4 to
091c314
Compare
…onversions Squashed onto develop cd6b428 (CI fixes from #5860). Original commits: - Add benchmarks for SAX parsing, value operations, JSON Pointer, and conversions - Time copies together with their destruction in the benchmarks - Time destroying the json in ToJsonStrings Signed-off-by: Niels Lohmann <mail@nlohmann.me>
nlohmann
force-pushed
the
benchmarks/value-operations
branch
from
October 21, 2026 08:41
091c314 to
c9c933a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The benchmark suite in
tests/benchmarkscovered only parsing, serialization and the binary formats. This adds 51 benchmarks for the rest of the everyday API, all on the existing test files:SaxParsesax_parse()with a handler that only counts events; the gap toParseStringis the cost of building the DOMCopy,CopyAssign,CopyRingCopyOnly,DestroyOnlyEqual==between two separate copies of a parsed documentIterateforloopsFlatten,Unflattenflatten()andunflatten()FlattenOrderedflatten()of anordered_json(canada is left out: it takes minutes with 3.12.0)Diff,Patchdiff()against the document with every eighth scalar changed, and applying that patchJsonPointerParse,JsonPointerToString,JsonPointerAt,JsonPointerContainsat()andcontains()GetVectorInt,GetVectorDouble,GetMapget<std::vector<std::int64_t>>(),get<std::vector<double>>(),get<std::map<std::string, json>>()(on the flattened document)ToJsonStrings/copy,ToJsonStrings/movejsonarray from astd::vectorof 100,000 strings, copied or moved, and destroying it again (timed, for the reason given below)The benchmarks use only API that 3.12.0 also has, so releases can be compared on them. While preparing the 3.13.0 performance post, they found the
unflatten(),operator==,get<std::map>()and destroy regressions against 3.12.0 that are now fixed in stack #5841.Copies (and the arrays
ToJsonStringscreates) are timed together with a destruction because how a document is freed shapes the heap the next copy allocates from. Since the faster destruction (#5762/#5767), part of the work it saves shows up in the next copy's allocations, so timing the copy alone made develop look slower than 3.12.0 (on glibc,citm_catalog0.6× in a standalone loop) although copying and destroying together got faster. Medians against 3.12.0,developheader:CopyCopyAssignCopyRingCopyOnlyDestroyOnlytests/benchmarks/README.mdlists the new benchmarks.There is no
Acceptbenchmark here, because the json_view stack (#5627 and below) adds one. Merging this with that stack, #5828 or #5833 conflicts only in added#includelines, benchmark definitions and README rows; keep both sides.Breaking changes
None. Only the benchmark suite changes; the library and its public API are untouched.
Testing
Built and run against the 3.12.0 header and against
develop(Apple Clang,-O3 -flto, C++11), and as part of the 3.13.0 release candidate. The copy benchmarks were also run on Linux (GCC 13, x86-64) against 3.12.0,developand the release candidate.This PR was written by Claude Code on behalf of @nlohmann.
🤖 Generated with Claude Code