From eab9c3d81c6c248c5b01ece9e7f2647fa7e85190 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 11 Nov 2025 14:37:43 -0400 Subject: [PATCH] Benchmark JSON parsing of real numbers Signed-off-by: Juan Cruz Viotti --- benchmark/json.cc | 118 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) diff --git a/benchmark/json.cc b/benchmark/json.cc index 34343864b..b11b4b856 100644 --- a/benchmark/json.cc +++ b/benchmark/json.cc @@ -1,6 +1,7 @@ #include -#include // assert +#include // std::ranges +#include // assert #include @@ -92,6 +93,120 @@ static void JSON_Parse_1(benchmark::State &state) { } } +static void JSON_Parse_Real(benchmark::State &state) { + const auto document{R"JSON([ + 1.0, + 2.0, + 3.5, + 4.25, + 5.125, + 6.0625, + 7.5, + 8.75, + 9.375, + 10.5, + 0.5, + 0.25, + 0.125, + 0.0625, + 0.03125, + 1024.0, + 2048.5, + 4096.25, + 8192.125, + 16384.0625, + -1.0, + -2.5, + -3.25, + -4.125, + -5.0625, + 100.5, + 200.25, + 300.125, + 400.0625, + 500.03125, + 1.0, + 2.0, + 3.5, + 4.25, + 5.125, + 6.0625, + 7.5, + 8.75, + 9.375, + 10.5, + 0.5, + 0.25, + 0.125, + 0.0625, + 0.03125, + 1024.0, + 2048.5, + 4096.25, + 8192.125, + 16384.0625, + -1.0, + -2.5, + -3.25, + -4.125, + -5.0625, + 100.5, + 200.25, + 300.125, + 400.0625, + 500.03125, + 1.0, + 2.0, + 3.5, + 4.25, + 5.125, + 6.0625, + 7.5, + 8.75, + 9.375, + 10.5, + 0.5, + 0.25, + 0.125, + 0.0625, + 0.03125, + 1024.0, + 2048.5, + 4096.25, + 8192.125, + 16384.0625, + -1.0, + -2.5, + -3.25, + -4.125, + -5.0625, + 100.5, + 200.25, + 300.125, + 400.0625, + 500.03125, + 1.0, + 2.0, + 3.5, + 4.25, + 5.125, + 6.0625, + 7.5, + 8.75, + 9.375, + 10.5 + ])JSON"}; + + assert(std::ranges::all_of(sourcemeta::core::parse_json(document).as_array(), + [](const auto &item) { return item.is_real(); })); + + for (auto _ : state) { + auto result{sourcemeta::core::parse_json(document)}; + assert(result.is_array()); + benchmark::DoNotOptimize(result); + } +} + static void JSON_Fast_Hash_Helm_Chart_Lock(benchmark::State &state) { // From `helm-chart-lock` const auto document{sourcemeta::core::parse_json(R"JSON({ @@ -311,6 +426,7 @@ static void JSON_Object_Defines_Miss_Too_Large(benchmark::State &state) { BENCHMARK(JSON_Array_Of_Objects_Unique); BENCHMARK(JSON_Parse_1); +BENCHMARK(JSON_Parse_Real); BENCHMARK(JSON_Fast_Hash_Helm_Chart_Lock); BENCHMARK(JSON_Equality_Helm_Chart_Lock); BENCHMARK(JSON_String_Equal)->Args({10})->Args({100});