Skip to content

Commit

Permalink
Add benchmarking code for url::can_parse
Browse files Browse the repository at this point in the history
  • Loading branch information
rmisev committed Jul 13, 2024
1 parent b708275 commit 99ad1ff
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions test/bench-url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,24 @@ int benchmark_txt(const char* file_name, uint64_t min_iters) {

// Run benchmark

ankerl::nanobench::Bench().minEpochIterations(min_iters).run("Upa URL", [&] {
ankerl::nanobench::Bench().minEpochIterations(min_iters).run("Upa url::parse", [&] {
upa::url url;

for (const auto& str_url : url_strings) {
url.parse(str_url, nullptr);
url.parse(str_url);

ankerl::nanobench::doNotOptimizeAway(url);
}
});

ankerl::nanobench::Bench().minEpochIterations(min_iters).run("Upa url::can_parse", [&] {
for (const auto& str_url : url_strings) {
bool ok = upa::url::can_parse(str_url);

ankerl::nanobench::doNotOptimizeAway(ok);
}
});

return 0;
}

Expand Down Expand Up @@ -81,14 +89,14 @@ int benchmark_wpt(const char* file_name, uint64_t min_iters) {

// Run benchmark

ankerl::nanobench::Bench().minEpochIterations(min_iters).run("Upa URL", [&] {
ankerl::nanobench::Bench().minEpochIterations(min_iters).run("Upa url::parse", [&] {
upa::url url;
upa::url url_base;

for (const auto& url_strings : url_samples) {
upa::url* ptr_base = nullptr;
if (!url_strings.second.empty()) {
if (!upa::success(url_base.parse(url_strings.second, nullptr)))
if (!upa::success(url_base.parse(url_strings.second)))
continue; // invalid base
ptr_base = &url_base;
}
Expand All @@ -98,6 +106,16 @@ int benchmark_wpt(const char* file_name, uint64_t min_iters) {
}
});

ankerl::nanobench::Bench().minEpochIterations(min_iters).run("Upa url::can_parse", [&] {
for (const auto& url_strings : url_samples) {
bool ok = url_strings.second.empty()
? upa::url::can_parse(url_strings.first)
: upa::url::can_parse(url_strings.first, url_strings.second);

ankerl::nanobench::doNotOptimizeAway(ok);
}
});

return 0;
}

Expand Down

0 comments on commit 99ad1ff

Please sign in to comment.