Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add can_parse to benchmarks #653

Merged
merged 3 commits into from
May 12, 2024
Merged
Changes from 2 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
61 changes: 61 additions & 0 deletions benchmarks/benchmark_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,67 @@ 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;
volatile size_t href_size = 0;
anonrig marked this conversation as resolved.
Show resolved Hide resolved

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
Loading