MCPcopy Create free account
hub / github.com/ada-url/ada / BasicBench_AdaURL_URLPattern_Test

Function BasicBench_AdaURL_URLPattern_Test

benchmarks/urlpattern.cpp:235–299  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233BENCHMARK(BasicBench_AdaURL_URLPattern_Exec);
234
235static void BasicBench_AdaURL_URLPattern_Test(benchmark::State& state) {
236 auto pattern =
237 ada::parse_url_pattern<ada::url_pattern_regex::std_regex_provider>(
238 "https://*example.com/*");
239 if (!pattern) {
240 state.SkipWithError("Failed to parse test pattern");
241 return;
242 }
243
244 // volatile to prevent optimizations.
245 volatile size_t success = 0;
246
247 for (auto _ : state) {
248 for (std::string& url_example : url_examples) {
249 auto result = pattern->test(url_example);
250 if (result) {
251 success++;
252 }
253 }
254 }
255 if (collector.has_events()) {
256 counters::event_aggregate aggregate{};
257 for (size_t i = 0; i < N; i++) {
258 std::atomic_thread_fence(std::memory_order_acquire);
259 collector.start();
260 for (std::string& url_example : url_examples) {
261 auto result = pattern->test(url_example);
262 if (result) {
263 success++;
264 }
265 }
266 std::atomic_thread_fence(std::memory_order_release);
267 counters::event_count allocate_count = collector.end();
268 aggregate << allocate_count;
269 }
270 state.counters["cycles/url"] =
271 aggregate.best.cycles() / std::size(url_examples);
272 state.counters["instructions/url"] =
273 aggregate.best.instructions() / std::size(url_examples);
274 state.counters["instructions/cycle"] =
275 aggregate.best.instructions() / aggregate.best.cycles();
276 state.counters["instructions/byte"] =
277 aggregate.best.instructions() / url_examples_bytes;
278 state.counters["instructions/ns"] =
279 aggregate.best.instructions() / aggregate.best.elapsed_ns();
280 state.counters["GHz"] =
281 aggregate.best.cycles() / aggregate.best.elapsed_ns();
282 state.counters["ns/url"] =
283 aggregate.best.elapsed_ns() / std::size(url_examples);
284 state.counters["cycle/byte"] = aggregate.best.cycles() / url_examples_bytes;
285 }
286 (void)success;
287 state.counters["time/byte"] = benchmark::Counter(
288 url_examples_bytes, benchmark::Counter::kIsIterationInvariantRate |
289 benchmark::Counter::kInvert);
290 state.counters["time/url"] =
291 benchmark::Counter(double(std::size(url_examples)),
292 benchmark::Counter::kIsIterationInvariantRate |

Callers

nothing calls this directly

Calls 2

testMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected