From 99ad1ffb36a40fb5288cbf3fedfc76074d1d3f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rimas=20Misevi=C4=8Dius?= Date: Sat, 13 Jul 2024 22:25:33 +0300 Subject: [PATCH] Add benchmarking code for url::can_parse --- test/bench-url.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/test/bench-url.cpp b/test/bench-url.cpp index dad604d..4b67bc5 100644 --- a/test/bench-url.cpp +++ b/test/bench-url.cpp @@ -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; } @@ -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; } @@ -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; }