Skip to content

Commit

Permalink
Add can_parse to benchmarks (#653)
Browse files Browse the repository at this point in the history
* Add can_parse to benchmark

* run clang-format

* Update benchmarks/benchmark_template.cpp

---------

Co-authored-by: Yagiz Nizipli <yagiz@nizipli.com>
  • Loading branch information
CarlosEduR and anonrig authored May 12, 2024
1 parent ccb7a26 commit e9dcc89
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions benchmarks/benchmark_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,66 @@ auto BasicBench_AdaURL_aggregator_href =
BasicBench_AdaURL<PARSE_AND_HREF, ada::url_aggregator>;
BENCHMARK(BasicBench_AdaURL_aggregator_href);

static void BasicBench_AdaURL_CanParse(benchmark::State& state) {
// volatile to prevent optimizations.
volatile size_t success = 0;

for (auto _ : state) {
for (std::string& url_string : url_examples) {
bool can_parse = ada::can_parse(url_string);
if (can_parse) {
success++;
}
}
}
if (collector.has_events()) {
event_aggregate aggregate{};
for (size_t i = 0; i < N; i++) {
std::atomic_thread_fence(std::memory_order_acquire);
collector.start();
for (std::string& url_string : url_examples) {
bool can_parse = ada::can_parse(url_string);
if (can_parse) {
success++;
}
}
std::atomic_thread_fence(std::memory_order_release);
event_count allocate_count = collector.end();
aggregate << allocate_count;
}
state.counters["cycles/url"] =
aggregate.best.cycles() / std::size(url_examples);
state.counters["instructions/url"] =
aggregate.best.instructions() / std::size(url_examples);
state.counters["instructions/cycle"] =
aggregate.best.instructions() / aggregate.best.cycles();
state.counters["instructions/byte"] =
aggregate.best.instructions() / url_examples_bytes;
state.counters["instructions/ns"] =
aggregate.best.instructions() / aggregate.best.elapsed_ns();
state.counters["GHz"] =
aggregate.best.cycles() / aggregate.best.elapsed_ns();
state.counters["ns/url"] =
aggregate.best.elapsed_ns() / std::size(url_examples);
state.counters["cycle/byte"] = aggregate.best.cycles() / url_examples_bytes;
}
(void)success;
state.counters["time/byte"] = benchmark::Counter(
url_examples_bytes, benchmark::Counter::kIsIterationInvariantRate |
benchmark::Counter::kInvert);
state.counters["time/url"] =
benchmark::Counter(double(std::size(url_examples)),
benchmark::Counter::kIsIterationInvariantRate |
benchmark::Counter::kInvert);
state.counters["speed"] = benchmark::Counter(
url_examples_bytes, benchmark::Counter::kIsIterationInvariantRate);
state.counters["url/s"] =
benchmark::Counter(double(std::size(url_examples)),
benchmark::Counter::kIsIterationInvariantRate);
}

BENCHMARK(BasicBench_AdaURL_CanParse);

#if ADA_url_whatwg_ENABLED
size_t count_whatwg_invalid() {
size_t how_many = 0;
Expand Down

0 comments on commit e9dcc89

Please sign in to comment.