From 98a141407d5358a050b65744ff2c6c43dd7e8c9f Mon Sep 17 00:00:00 2001 From: ayush-singh-0601 Date: Thu, 10 Sep 2026 21:45:06 +0530 Subject: [PATCH 1/3] Cut test suite runtime in binary roundtrips and integer sweeps The Linux CI jobs pass --no-skip, so skip() does not help there. Parse each corpus file once in the binary roundtrip loops instead of four times. Sample the 16-bit integer ranges with stride 7 (still hits every low byte) and always keep the endpoints. Also drop the 5M-node parse test to 500k, which still covers the non-recursive destructor, and move jeopardy.json into its own skipped test so the cheaper binary-format size checks actually run. See #5418. Signed-off-by: ayush-singh-0601 --- tests/src/test_utils.hpp | 18 +++++++ tests/src/unit-binary_formats.cpp | 80 +++++++++++++++---------------- tests/src/unit-bjdata.cpp | 32 +++---------- tests/src/unit-cbor.cpp | 42 ++++------------ tests/src/unit-large_json.cpp | 2 +- tests/src/unit-msgpack.cpp | 40 +++------------- tests/src/unit-ubjson.cpp | 40 +++------------- 7 files changed, 88 insertions(+), 166 deletions(-) diff --git a/tests/src/test_utils.hpp b/tests/src/test_utils.hpp index 4c81a8ef41a..48ede9374c1 100644 --- a/tests/src/test_utils.hpp +++ b/tests/src/test_utils.hpp @@ -9,6 +9,7 @@ #pragma once #include // uint8_t +#include // size_t #include // ifstream, istreambuf_iterator, ios #include // vector @@ -24,6 +25,23 @@ namespace utils template inline void ignore_return_value(T&& /*unused*/) noexcept {} +// Walk [first, last] inclusive with a stride, always visiting last. +// stride 7 is coprime to 256, so every low-byte residue is still hit. +template +T next_integer_sample(T i, T last, T stride) +{ + if (i >= last) + { + return static_cast(last + 1); + } + if (stride > 0 && i > static_cast(last - stride)) + { + return last; + } + const T n = static_cast(i + stride); + return n < last ? n : last; +} + inline std::vector read_binary_file(const std::string& filename) { std::ifstream file(filename, std::ios::binary); diff --git a/tests/src/unit-binary_formats.cpp b/tests/src/unit-binary_formats.cpp index 0c084b720a8..2d4797faac6 100644 --- a/tests/src/unit-binary_formats.cpp +++ b/tests/src/unit-binary_formats.cpp @@ -14,7 +14,7 @@ using nlohmann::json; #include #include "make_test_data_available.hpp" -TEST_CASE("Binary Formats" * doctest::skip()) +TEST_CASE("Binary Formats") { SECTION("canada.json") { @@ -133,45 +133,6 @@ TEST_CASE("Binary Formats" * doctest::skip()) CHECK((100.0 * double(ubjson_3_size) / double(json_size)) == Approx(84.963)); } - SECTION("jeopardy.json") - { - const auto* filename = TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json"; - json j = json::parse(std::ifstream(filename)); - - const auto json_size = j.dump().size(); - const auto bjdata_1_size = json::to_bjdata(j).size(); - const auto bjdata_2_size = json::to_bjdata(j, true).size(); - const auto bjdata_3_size = json::to_bjdata(j, true, true).size(); - const auto bson_size = json::to_bson({{"", j}}).size(); // wrap array in object for BSON - const auto cbor_size = json::to_cbor(j).size(); - const auto msgpack_size = json::to_msgpack(j).size(); - const auto ubjson_1_size = json::to_ubjson(j).size(); - const auto ubjson_2_size = json::to_ubjson(j, true).size(); - const auto ubjson_3_size = json::to_ubjson(j, true, true).size(); - - CHECK(json_size == 52508728); - CHECK(bjdata_1_size == 50710965); - CHECK(bjdata_2_size == 51144830); - CHECK(bjdata_3_size == 51144830); - CHECK(bson_size == 56008520); - CHECK(cbor_size == 46187320); - CHECK(msgpack_size == 46158575); - CHECK(ubjson_1_size == 50710965); - CHECK(ubjson_2_size == 51144830); - CHECK(ubjson_3_size == 49861422); - - CHECK((100.0 * double(json_size) / double(json_size)) == Approx(100.0)); - CHECK((100.0 * double(bjdata_1_size) / double(json_size)) == Approx(96.576)); - CHECK((100.0 * double(bjdata_2_size) / double(json_size)) == Approx(97.402)); - CHECK((100.0 * double(bjdata_3_size) / double(json_size)) == Approx(97.402)); - CHECK((100.0 * double(bson_size) / double(json_size)) == Approx(106.665)); - CHECK((100.0 * double(cbor_size) / double(json_size)) == Approx(87.961)); - CHECK((100.0 * double(msgpack_size) / double(json_size)) == Approx(87.906)); - CHECK((100.0 * double(ubjson_1_size) / double(json_size)) == Approx(96.576)); - CHECK((100.0 * double(ubjson_2_size) / double(json_size)) == Approx(97.402)); - CHECK((100.0 * double(ubjson_3_size) / double(json_size)) == Approx(94.958)); - } - SECTION("sample.json") { const auto* filename = TEST_DATA_DIRECTORY "/json_testsuite/sample.json"; @@ -209,3 +170,42 @@ TEST_CASE("Binary Formats" * doctest::skip()) CHECK((100.0 * double(ubjson_3_size) / double(json_size)) == Approx(89.450)); } } + +TEST_CASE("Binary Formats jeopardy.json" * doctest::skip()) +{ + const auto* filename = TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json"; + json j = json::parse(std::ifstream(filename)); + + const auto json_size = j.dump().size(); + const auto bjdata_1_size = json::to_bjdata(j).size(); + const auto bjdata_2_size = json::to_bjdata(j, true).size(); + const auto bjdata_3_size = json::to_bjdata(j, true, true).size(); + const auto bson_size = json::to_bson({{"", j}}).size(); // wrap array in object for BSON + const auto cbor_size = json::to_cbor(j).size(); + const auto msgpack_size = json::to_msgpack(j).size(); + const auto ubjson_1_size = json::to_ubjson(j).size(); + const auto ubjson_2_size = json::to_ubjson(j, true).size(); + const auto ubjson_3_size = json::to_ubjson(j, true, true).size(); + + CHECK(json_size == 52508728); + CHECK(bjdata_1_size == 50710965); + CHECK(bjdata_2_size == 51144830); + CHECK(bjdata_3_size == 51144830); + CHECK(bson_size == 56008520); + CHECK(cbor_size == 46187320); + CHECK(msgpack_size == 46158575); + CHECK(ubjson_1_size == 50710965); + CHECK(ubjson_2_size == 51144830); + CHECK(ubjson_3_size == 49861422); + + CHECK((100.0 * double(json_size) / double(json_size)) == Approx(100.0)); + CHECK((100.0 * double(bjdata_1_size) / double(json_size)) == Approx(96.576)); + CHECK((100.0 * double(bjdata_2_size) / double(json_size)) == Approx(97.402)); + CHECK((100.0 * double(bjdata_3_size) / double(json_size)) == Approx(97.402)); + CHECK((100.0 * double(bson_size) / double(json_size)) == Approx(106.665)); + CHECK((100.0 * double(cbor_size) / double(json_size)) == Approx(87.961)); + CHECK((100.0 * double(msgpack_size) / double(json_size)) == Approx(87.906)); + CHECK((100.0 * double(ubjson_1_size) / double(json_size)) == Approx(96.576)); + CHECK((100.0 * double(ubjson_2_size) / double(json_size)) == Approx(97.402)); + CHECK((100.0 * double(ubjson_3_size) / double(json_size)) == Approx(94.958)); +} diff --git a/tests/src/unit-bjdata.cpp b/tests/src/unit-bjdata.cpp index 334259fb73f..3b760d0cfb2 100644 --- a/tests/src/unit-bjdata.cpp +++ b/tests/src/unit-bjdata.cpp @@ -417,7 +417,7 @@ TEST_CASE("BJData") SECTION("-32768..-129 (int16)") { - for (int32_t i = -32768; i <= -129; ++i) + for (int32_t i = -32768; i <= -129; i = utils::next_integer_sample(i, static_cast(-129), 7)) { CAPTURE(i) @@ -577,7 +577,7 @@ TEST_CASE("BJData") SECTION("256..32767 (int16)") { - for (size_t i = 256; i <= 32767; ++i) + for (size_t i = 256; i <= 32767; i = utils::next_integer_sample(i, static_cast(32767), static_cast(7))) { CAPTURE(i) @@ -910,7 +910,7 @@ TEST_CASE("BJData") SECTION("256..32767 (int16)") { - for (size_t i = 256; i <= 32767; ++i) + for (size_t i = 256; i <= 32767; i = utils::next_integer_sample(i, static_cast(32767), static_cast(7))) { CAPTURE(i) @@ -4251,45 +4251,27 @@ TEST_CASE("BJData roundtrips" * doctest::skip()) { CAPTURE(filename) + std::ifstream f_json(filename); + const json j1 = json::parse(f_json); + auto packed = utils::read_binary_file(filename + ".bjdata"); + { INFO_WITH_TEMP(filename + ": std::vector"); - // parse JSON file - std::ifstream f_json(filename); - const json j1 = json::parse(f_json); - - // parse BJData file - auto packed = utils::read_binary_file(filename + ".bjdata"); json j2; CHECK_NOTHROW(j2 = json::from_bjdata(packed)); - - // compare parsed JSON values CHECK(j1 == j2); } { INFO_WITH_TEMP(filename + ": std::ifstream"); - // parse JSON file - std::ifstream f_json(filename); - const json j1 = json::parse(f_json); - - // parse BJData file std::ifstream f_bjdata(filename + ".bjdata", std::ios::binary); json j2; CHECK_NOTHROW(j2 = json::from_bjdata(f_bjdata)); - - // compare parsed JSON values CHECK(j1 == j2); } { INFO_WITH_TEMP(filename + ": output to output adapters"); - // parse JSON file - std::ifstream f_json(filename); - json const j1 = json::parse(f_json); - - // parse BJData file - auto packed = utils::read_binary_file(filename + ".bjdata"); - { INFO_WITH_TEMP(filename + ": output adapters: std::vector"); std::vector vec; diff --git a/tests/src/unit-cbor.cpp b/tests/src/unit-cbor.cpp index 4c9107517f5..df807a7d8d1 100644 --- a/tests/src/unit-cbor.cpp +++ b/tests/src/unit-cbor.cpp @@ -290,7 +290,7 @@ TEST_CASE("CBOR") SECTION("-65536..-257") { - for (int32_t i = -65536; i <= -257; ++i) + for (int32_t i = -65536; i <= -257; i = utils::next_integer_sample(i, static_cast(-257), 7)) { CAPTURE(i) @@ -478,7 +478,7 @@ TEST_CASE("CBOR") SECTION("256..65535") { - for (size_t i = 256; i <= 65535; ++i) + for (size_t i = 256; i <= 65535; i = utils::next_integer_sample(i, static_cast(65535), static_cast(7))) { CAPTURE(i) @@ -613,7 +613,7 @@ TEST_CASE("CBOR") SECTION("-32768..-129 (int 16)") { - for (int16_t i = -32768; i <= static_cast(-129); ++i) + for (int16_t i = -32768; i <= static_cast(-129); i = utils::next_integer_sample(i, static_cast(-129), static_cast(7))) { CAPTURE(i) @@ -718,7 +718,7 @@ TEST_CASE("CBOR") SECTION("256..65535 (two-byte uint16_t)") { - for (size_t i = 256; i <= 65535; ++i) + for (size_t i = 256; i <= 65535; i = utils::next_integer_sample(i, static_cast(65535), static_cast(7))) { CAPTURE(i) @@ -2429,60 +2429,34 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) { CAPTURE(filename) + std::ifstream f_json(filename); + const json j1 = json::parse(f_json); + const auto packed = utils::read_binary_file(filename + ".cbor"); + { INFO_WITH_TEMP(filename + ": std::vector"); - // parse JSON file - std::ifstream f_json(filename); - const json j1 = json::parse(f_json); - - // parse CBOR file - const auto packed = utils::read_binary_file(filename + ".cbor"); json j2; CHECK_NOTHROW(j2 = json::from_cbor(packed)); - - // compare parsed JSON values CHECK(j1 == j2); } { INFO_WITH_TEMP(filename + ": std::ifstream"); - // parse JSON file - std::ifstream f_json(filename); - const json j1 = json::parse(f_json); - - // parse CBOR file std::ifstream f_cbor(filename + ".cbor", std::ios::binary); json j2; CHECK_NOTHROW(j2 = json::from_cbor(f_cbor)); - - // compare parsed JSON values CHECK(j1 == j2); } { INFO_WITH_TEMP(filename + ": uint8_t* and size"); - // parse JSON file - std::ifstream f_json(filename); - const json j1 = json::parse(f_json); - - // parse CBOR file - const auto packed = utils::read_binary_file(filename + ".cbor"); json j2; CHECK_NOTHROW(j2 = json::from_cbor({packed.data(), packed.size()})); - - // compare parsed JSON values CHECK(j1 == j2); } { INFO_WITH_TEMP(filename + ": output to output adapters"); - // parse JSON file - std::ifstream f_json(filename); - json const j1 = json::parse(f_json); - - // parse CBOR file - const auto packed = utils::read_binary_file(filename + ".cbor"); - if (exclude_packed.count(filename) == 0u) { { diff --git a/tests/src/unit-large_json.cpp b/tests/src/unit-large_json.cpp index 98d16e33694..0107d0f9471 100644 --- a/tests/src/unit-large_json.cpp +++ b/tests/src/unit-large_json.cpp @@ -17,7 +17,7 @@ TEST_CASE("tests on very large JSONs") { SECTION("issue #1419 - Segmentation fault (stack overflow) due to unbounded recursion") { - const auto depth = 5000000; + const auto depth = 500000; std::string s(static_cast(2 * depth), '['); std::fill(s.begin() + depth, s.end(), ']'); diff --git a/tests/src/unit-msgpack.cpp b/tests/src/unit-msgpack.cpp index a8892081d37..f1bb08c0ce7 100644 --- a/tests/src/unit-msgpack.cpp +++ b/tests/src/unit-msgpack.cpp @@ -255,7 +255,7 @@ TEST_CASE("MessagePack") SECTION("256..65535 (int 16)") { - for (size_t i = 256; i <= 65535; ++i) + for (size_t i = 256; i <= 65535; i = utils::next_integer_sample(i, static_cast(65535), static_cast(7))) { CAPTURE(i) @@ -440,7 +440,7 @@ TEST_CASE("MessagePack") SECTION("-32768..-129 (int 16)") { - for (int16_t i = -32768; i <= static_cast(-129); ++i) + for (int16_t i = -32768; i <= static_cast(-129); i = utils::next_integer_sample(i, static_cast(-129), static_cast(7))) { CAPTURE(i) @@ -646,7 +646,7 @@ TEST_CASE("MessagePack") SECTION("256..65535 (uint 16)") { - for (size_t i = 256; i <= 65535; ++i) + for (size_t i = 256; i <= 65535; i = utils::next_integer_sample(i, static_cast(65535), static_cast(7))) { CAPTURE(i) @@ -1983,60 +1983,34 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip()) { CAPTURE(filename) + std::ifstream f_json(filename); + const json j1 = json::parse(f_json); + auto packed = utils::read_binary_file(filename + ".msgpack"); + { INFO_WITH_TEMP(filename + ": std::vector"); - // parse JSON file - std::ifstream f_json(filename); - const json j1 = json::parse(f_json); - - // parse MessagePack file - auto packed = utils::read_binary_file(filename + ".msgpack"); json j2; CHECK_NOTHROW(j2 = json::from_msgpack(packed)); - - // compare parsed JSON values CHECK(j1 == j2); } { INFO_WITH_TEMP(filename + ": std::ifstream"); - // parse JSON file - std::ifstream f_json(filename); - const json j1 = json::parse(f_json); - - // parse MessagePack file std::ifstream f_msgpack(filename + ".msgpack", std::ios::binary); json j2; CHECK_NOTHROW(j2 = json::from_msgpack(f_msgpack)); - - // compare parsed JSON values CHECK(j1 == j2); } { INFO_WITH_TEMP(filename + ": uint8_t* and size"); - // parse JSON file - std::ifstream f_json(filename); - const json j1 = json::parse(f_json); - - // parse MessagePack file - auto packed = utils::read_binary_file(filename + ".msgpack"); json j2; CHECK_NOTHROW(j2 = json::from_msgpack({packed.data(), packed.size()})); - - // compare parsed JSON values CHECK(j1 == j2); } { INFO_WITH_TEMP(filename + ": output to output adapters"); - // parse JSON file - std::ifstream f_json(filename); - json const j1 = json::parse(f_json); - - // parse MessagePack file - auto packed = utils::read_binary_file(filename + ".msgpack"); - if (exclude_packed.count(filename) == 0u) { { diff --git a/tests/src/unit-ubjson.cpp b/tests/src/unit-ubjson.cpp index aafbbf5a481..92d2a06801a 100644 --- a/tests/src/unit-ubjson.cpp +++ b/tests/src/unit-ubjson.cpp @@ -264,7 +264,7 @@ TEST_CASE("UBJSON") SECTION("-32768..-129 (int16)") { - for (int32_t i = -32768; i <= -129; ++i) + for (int32_t i = -32768; i <= -129; i = utils::next_integer_sample(i, static_cast(-129), 7)) { CAPTURE(i) @@ -424,7 +424,7 @@ TEST_CASE("UBJSON") SECTION("256..32767 (int16)") { - for (size_t i = 256; i <= 32767; ++i) + for (size_t i = 256; i <= 32767; i = utils::next_integer_sample(i, static_cast(32767), static_cast(7))) { CAPTURE(i) @@ -630,7 +630,7 @@ TEST_CASE("UBJSON") SECTION("256..32767 (int16)") { - for (size_t i = 256; i <= 32767; ++i) + for (size_t i = 256; i <= 32767; i = utils::next_integer_sample(i, static_cast(32767), static_cast(7))) { CAPTURE(i) @@ -2869,60 +2869,34 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip()) { CAPTURE(filename) + std::ifstream f_json(filename); + json const j1 = json::parse(f_json); + auto const packed = utils::read_binary_file(filename + ".ubjson"); + { INFO_WITH_TEMP(filename + ": std::vector"); - // parse JSON file - std::ifstream f_json(filename); - json const j1 = json::parse(f_json); - - // parse UBJSON file - auto const packed = utils::read_binary_file(filename + ".ubjson"); json j2; CHECK_NOTHROW(j2 = json::from_ubjson(packed)); - - // compare parsed JSON values CHECK(j1 == j2); } { INFO_WITH_TEMP(filename + ": std::ifstream"); - // parse JSON file - std::ifstream f_json(filename); - json const j1 = json::parse(f_json); - - // parse UBJSON file std::ifstream f_ubjson(filename + ".ubjson", std::ios::binary); json j2; CHECK_NOTHROW(j2 = json::from_ubjson(f_ubjson)); - - // compare parsed JSON values CHECK(j1 == j2); } { INFO_WITH_TEMP(filename + ": uint8_t* and size"); - // parse JSON file - std::ifstream f_json(filename); - const json j1 = json::parse(f_json); - - // parse UBJSON file - auto const packed = utils::read_binary_file(filename + ".ubjson"); json j2; CHECK_NOTHROW(j2 = json::from_ubjson({packed.data(), packed.size()})); - - // compare parsed JSON values CHECK(j1 == j2); } { INFO_WITH_TEMP(filename + ": output to output adapters"); - // parse JSON file - std::ifstream f_json(filename); - json const j1 = json::parse(f_json); - - // parse UBJSON file - auto const packed = utils::read_binary_file(filename + ".ubjson"); - { INFO_WITH_TEMP(filename + ": output adapters: std::vector"); std::vector vec; From 60eb7229678b97da64d8c74620745acafd8fbae2 Mon Sep 17 00:00:00 2001 From: ayush-singh-0601 Date: Wed, 23 Sep 2026 16:10:13 +0530 Subject: [PATCH 2/3] Drop useless int32_t casts in the sampled integer loops ci_test_gcc compiles with -Werror=useless-cast. On that compiler int32_t is int, so static_cast of the loop bound is an error. The bounds are already int, and the sampled values do not change. Signed-off-by: ayush-singh-0601 --- tests/src/unit-bjdata.cpp | 2 +- tests/src/unit-cbor.cpp | 2 +- tests/src/unit-ubjson.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/src/unit-bjdata.cpp b/tests/src/unit-bjdata.cpp index 3b760d0cfb2..49b986ceef5 100644 --- a/tests/src/unit-bjdata.cpp +++ b/tests/src/unit-bjdata.cpp @@ -417,7 +417,7 @@ TEST_CASE("BJData") SECTION("-32768..-129 (int16)") { - for (int32_t i = -32768; i <= -129; i = utils::next_integer_sample(i, static_cast(-129), 7)) + for (int32_t i = -32768; i <= -129; i = utils::next_integer_sample(i, -129, 7)) { CAPTURE(i) diff --git a/tests/src/unit-cbor.cpp b/tests/src/unit-cbor.cpp index df807a7d8d1..515e758f436 100644 --- a/tests/src/unit-cbor.cpp +++ b/tests/src/unit-cbor.cpp @@ -290,7 +290,7 @@ TEST_CASE("CBOR") SECTION("-65536..-257") { - for (int32_t i = -65536; i <= -257; i = utils::next_integer_sample(i, static_cast(-257), 7)) + for (int32_t i = -65536; i <= -257; i = utils::next_integer_sample(i, -257, 7)) { CAPTURE(i) diff --git a/tests/src/unit-ubjson.cpp b/tests/src/unit-ubjson.cpp index 92d2a06801a..9f371173599 100644 --- a/tests/src/unit-ubjson.cpp +++ b/tests/src/unit-ubjson.cpp @@ -264,7 +264,7 @@ TEST_CASE("UBJSON") SECTION("-32768..-129 (int16)") { - for (int32_t i = -32768; i <= -129; i = utils::next_integer_sample(i, static_cast(-129), 7)) + for (int32_t i = -32768; i <= -129; i = utils::next_integer_sample(i, -129, 7)) { CAPTURE(i) From d67910b337c6cecc8561765253ece42a1067653f Mon Sep 17 00:00:00 2001 From: ayush-singh-0601 Date: Sat, 26 Sep 2026 17:33:27 +0530 Subject: [PATCH 3/3] Revert unit-binary_formats.cpp to develop and fix comment Revert tests/src/unit-binary_formats.cpp to its develop state. The test-case split made valgrind jobs slower instead of faster, because the cheaper corpus files (canada/twitter/citm/sample) now ran under valgrind where they never did before. Fix the next_integer_sample comment: the function has no 'first' parameter, so describe what the function actually does. Signed-off-by: ayush-singh-0601 --- tests/src/test_utils.hpp | 2 +- tests/src/unit-binary_formats.cpp | 80 +++++++++++++++---------------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/tests/src/test_utils.hpp b/tests/src/test_utils.hpp index 48ede9374c1..b2a381fb0f6 100644 --- a/tests/src/test_utils.hpp +++ b/tests/src/test_utils.hpp @@ -25,7 +25,7 @@ namespace utils template inline void ignore_return_value(T&& /*unused*/) noexcept {} -// Walk [first, last] inclusive with a stride, always visiting last. +// Advance i toward last (inclusive) by stride, always visiting last. // stride 7 is coprime to 256, so every low-byte residue is still hit. template T next_integer_sample(T i, T last, T stride) diff --git a/tests/src/unit-binary_formats.cpp b/tests/src/unit-binary_formats.cpp index 2d4797faac6..0c084b720a8 100644 --- a/tests/src/unit-binary_formats.cpp +++ b/tests/src/unit-binary_formats.cpp @@ -14,7 +14,7 @@ using nlohmann::json; #include #include "make_test_data_available.hpp" -TEST_CASE("Binary Formats") +TEST_CASE("Binary Formats" * doctest::skip()) { SECTION("canada.json") { @@ -133,6 +133,45 @@ TEST_CASE("Binary Formats") CHECK((100.0 * double(ubjson_3_size) / double(json_size)) == Approx(84.963)); } + SECTION("jeopardy.json") + { + const auto* filename = TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json"; + json j = json::parse(std::ifstream(filename)); + + const auto json_size = j.dump().size(); + const auto bjdata_1_size = json::to_bjdata(j).size(); + const auto bjdata_2_size = json::to_bjdata(j, true).size(); + const auto bjdata_3_size = json::to_bjdata(j, true, true).size(); + const auto bson_size = json::to_bson({{"", j}}).size(); // wrap array in object for BSON + const auto cbor_size = json::to_cbor(j).size(); + const auto msgpack_size = json::to_msgpack(j).size(); + const auto ubjson_1_size = json::to_ubjson(j).size(); + const auto ubjson_2_size = json::to_ubjson(j, true).size(); + const auto ubjson_3_size = json::to_ubjson(j, true, true).size(); + + CHECK(json_size == 52508728); + CHECK(bjdata_1_size == 50710965); + CHECK(bjdata_2_size == 51144830); + CHECK(bjdata_3_size == 51144830); + CHECK(bson_size == 56008520); + CHECK(cbor_size == 46187320); + CHECK(msgpack_size == 46158575); + CHECK(ubjson_1_size == 50710965); + CHECK(ubjson_2_size == 51144830); + CHECK(ubjson_3_size == 49861422); + + CHECK((100.0 * double(json_size) / double(json_size)) == Approx(100.0)); + CHECK((100.0 * double(bjdata_1_size) / double(json_size)) == Approx(96.576)); + CHECK((100.0 * double(bjdata_2_size) / double(json_size)) == Approx(97.402)); + CHECK((100.0 * double(bjdata_3_size) / double(json_size)) == Approx(97.402)); + CHECK((100.0 * double(bson_size) / double(json_size)) == Approx(106.665)); + CHECK((100.0 * double(cbor_size) / double(json_size)) == Approx(87.961)); + CHECK((100.0 * double(msgpack_size) / double(json_size)) == Approx(87.906)); + CHECK((100.0 * double(ubjson_1_size) / double(json_size)) == Approx(96.576)); + CHECK((100.0 * double(ubjson_2_size) / double(json_size)) == Approx(97.402)); + CHECK((100.0 * double(ubjson_3_size) / double(json_size)) == Approx(94.958)); + } + SECTION("sample.json") { const auto* filename = TEST_DATA_DIRECTORY "/json_testsuite/sample.json"; @@ -170,42 +209,3 @@ TEST_CASE("Binary Formats") CHECK((100.0 * double(ubjson_3_size) / double(json_size)) == Approx(89.450)); } } - -TEST_CASE("Binary Formats jeopardy.json" * doctest::skip()) -{ - const auto* filename = TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json"; - json j = json::parse(std::ifstream(filename)); - - const auto json_size = j.dump().size(); - const auto bjdata_1_size = json::to_bjdata(j).size(); - const auto bjdata_2_size = json::to_bjdata(j, true).size(); - const auto bjdata_3_size = json::to_bjdata(j, true, true).size(); - const auto bson_size = json::to_bson({{"", j}}).size(); // wrap array in object for BSON - const auto cbor_size = json::to_cbor(j).size(); - const auto msgpack_size = json::to_msgpack(j).size(); - const auto ubjson_1_size = json::to_ubjson(j).size(); - const auto ubjson_2_size = json::to_ubjson(j, true).size(); - const auto ubjson_3_size = json::to_ubjson(j, true, true).size(); - - CHECK(json_size == 52508728); - CHECK(bjdata_1_size == 50710965); - CHECK(bjdata_2_size == 51144830); - CHECK(bjdata_3_size == 51144830); - CHECK(bson_size == 56008520); - CHECK(cbor_size == 46187320); - CHECK(msgpack_size == 46158575); - CHECK(ubjson_1_size == 50710965); - CHECK(ubjson_2_size == 51144830); - CHECK(ubjson_3_size == 49861422); - - CHECK((100.0 * double(json_size) / double(json_size)) == Approx(100.0)); - CHECK((100.0 * double(bjdata_1_size) / double(json_size)) == Approx(96.576)); - CHECK((100.0 * double(bjdata_2_size) / double(json_size)) == Approx(97.402)); - CHECK((100.0 * double(bjdata_3_size) / double(json_size)) == Approx(97.402)); - CHECK((100.0 * double(bson_size) / double(json_size)) == Approx(106.665)); - CHECK((100.0 * double(cbor_size) / double(json_size)) == Approx(87.961)); - CHECK((100.0 * double(msgpack_size) / double(json_size)) == Approx(87.906)); - CHECK((100.0 * double(ubjson_1_size) / double(json_size)) == Approx(96.576)); - CHECK((100.0 * double(ubjson_2_size) / double(json_size)) == Approx(97.402)); - CHECK((100.0 * double(ubjson_3_size) / double(json_size)) == Approx(94.958)); -}