From 33db1114a7917467c5563abc49979a35ff1cdd4d Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 14 Sep 2026 20:21:16 -0300 Subject: [PATCH 1/2] Add one more markdown benchmark case Signed-off-by: Juan Cruz Viotti --- benchmark/markdown.cc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/benchmark/markdown.cc b/benchmark/markdown.cc index ae3ed16d90..4b77f731cd 100644 --- a/benchmark/markdown.cc +++ b/benchmark/markdown.cc @@ -4,6 +4,7 @@ #include // std::size_t #include // std::string, std::to_string +#include // std::vector static auto repeat(const std::string &pattern, const std::size_t count) -> std::string { @@ -99,5 +100,35 @@ static void Markdown_To_HTML_Pathological(benchmark::State &state) { } } +// Many short inputs, like the descriptions that schema documentation renders, +// where the cost of every call matters more than the cost of every byte +// NOLINTNEXTLINE(readability-identifier-naming) +static void Markdown_To_HTML_Short_Descriptions(benchmark::State &state) { + std::vector inputs; + inputs.reserve(1000); + for (std::size_t index = 0; index < 250; ++index) { + const auto number{std::to_string(index)}; + inputs.push_back( + std::string{"The identifier of resource "}.append(number).append(".")); + inputs.push_back(std::string{"A `string` that must match the *pattern* "} + .append(number) + .append(".")); + inputs.push_back( + std::string{"See [the documentation](https://sourcemeta.com/"} + .append(number) + .append(") for **details**.")); + inputs.push_back( + std::string{"- First option\n- Second option "}.append(number)); + } + + for (auto iteration : state) { + for (const auto &input : inputs) { + auto result{sourcemeta::core::markdown_to_html(input)}; + benchmark::DoNotOptimize(result); + } + } +} + BENCHMARK(Markdown_To_HTML_Realistic_Document); BENCHMARK(Markdown_To_HTML_Pathological); +BENCHMARK(Markdown_To_HTML_Short_Descriptions); From e420b787903139f7017dfe7d6f23f4ec6fc19a95 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 14 Sep 2026 20:26:54 -0300 Subject: [PATCH 2/2] Fix Signed-off-by: Juan Cruz Viotti --- benchmark/markdown.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/benchmark/markdown.cc b/benchmark/markdown.cc index 4b77f731cd..ce4b18ceb4 100644 --- a/benchmark/markdown.cc +++ b/benchmark/markdown.cc @@ -101,7 +101,8 @@ static void Markdown_To_HTML_Pathological(benchmark::State &state) { } // Many short inputs, like the descriptions that schema documentation renders, -// where the cost of every call matters more than the cost of every byte +// where the cost of every call matters more than the cost of every byte, so +// every iteration converts the next input of the corpus // NOLINTNEXTLINE(readability-identifier-naming) static void Markdown_To_HTML_Short_Descriptions(benchmark::State &state) { std::vector inputs; @@ -121,10 +122,13 @@ static void Markdown_To_HTML_Short_Descriptions(benchmark::State &state) { std::string{"- First option\n- Second option "}.append(number)); } + std::size_t position{0}; for (auto iteration : state) { - for (const auto &input : inputs) { - auto result{sourcemeta::core::markdown_to_html(input)}; - benchmark::DoNotOptimize(result); + auto result{sourcemeta::core::markdown_to_html(inputs[position])}; + benchmark::DoNotOptimize(result); + position += 1; + if (position == inputs.size()) { + position = 0; } } }