Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions benchmark/markdown.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <cstddef> // std::size_t
#include <string> // std::string, std::to_string
#include <vector> // std::vector

static auto repeat(const std::string &pattern, const std::size_t count)
-> std::string {
Expand Down Expand Up @@ -99,5 +100,39 @@ 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, 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<std::string> 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));
}

std::size_t position{0};
for (auto iteration : state) {
auto result{sourcemeta::core::markdown_to_html(inputs[position])};
benchmark::DoNotOptimize(result);
position += 1;
if (position == inputs.size()) {
position = 0;
}
}
}

BENCHMARK(Markdown_To_HTML_Realistic_Document);
BENCHMARK(Markdown_To_HTML_Pathological);
BENCHMARK(Markdown_To_HTML_Short_Descriptions);