@@ -367,6 +367,97 @@ BENCHMARK(BasicBench_BoostURL);
367367// BENCHMARK(BasicBench_BoostURL_just_parse);
368368#endif // ADA_BOOST_ENABLED
369369
370+ #if ADA_ZURI_ENABLED
371+ #include < zuri.h>
372+
373+ size_t count_zuri_invalid () {
374+ size_t how_many = 0 ;
375+ for (std::string& url_string : url_examples) {
376+ struct zuri2k uri;
377+ zuri_error err = zuri_parse2k (&uri, url_string.c_str ());
378+ if (err) how_many++;
379+ }
380+ return how_many;
381+ }
382+
383+ // ZURI follows RFC3986
384+ template <bool just_parse = false >
385+ static void BasicBench_ZURI (benchmark::State& state) {
386+ // volatile to prevent optimizations.
387+ volatile size_t success = 0 ;
388+ volatile size_t href_size = 0 ;
389+
390+ for (auto _ : state) {
391+ for (std::string& url_string : url_examples) {
392+ struct zuri2k uri;
393+ benchmark::DoNotOptimize (uri);
394+ zuri_error err = zuri_parse2k (&uri, url_string.c_str ());
395+ if (!err) {
396+ success++;
397+ if constexpr (!just_parse) {
398+ char buf[2048 ];
399+ benchmark::DoNotOptimize (href_size +=
400+ zuri_read2k (&uri, &buf[0 ], sizeof (buf)));
401+ }
402+ }
403+ }
404+ }
405+ if (collector.has_events ()) {
406+ event_aggregate aggregate{};
407+ for (size_t i = 0 ; i < N; i++) {
408+ std::atomic_thread_fence (std::memory_order_acquire);
409+ collector.start ();
410+ for (std::string& url_string : url_examples) {
411+ struct zuri2k uri;
412+ benchmark::DoNotOptimize (uri);
413+ zuri_error err = zuri_parse2k (&uri, url_string.c_str ());
414+ if (!err) {
415+ success++;
416+ if constexpr (!just_parse) {
417+ char buf[2048 ];
418+ benchmark::DoNotOptimize (href_size +=
419+ zuri_read2k (&uri, &buf[0 ], sizeof (buf)));
420+ }
421+ }
422+ }
423+ std::atomic_thread_fence (std::memory_order_release);
424+ event_count allocate_count = collector.end ();
425+ aggregate << allocate_count;
426+ }
427+ state.counters [" cycles/url" ] =
428+ aggregate.best .cycles () / std::size (url_examples);
429+ state.counters [" instructions/url" ] =
430+ aggregate.best .instructions () / std::size (url_examples);
431+ state.counters [" instructions/cycle" ] =
432+ aggregate.best .instructions () / aggregate.best .cycles ();
433+ state.counters [" instructions/byte" ] =
434+ aggregate.best .instructions () / url_examples_bytes;
435+ state.counters [" instructions/ns" ] =
436+ aggregate.best .instructions () / aggregate.best .elapsed_ns ();
437+ state.counters [" GHz" ] =
438+ aggregate.best .cycles () / aggregate.best .elapsed_ns ();
439+ state.counters [" ns/url" ] =
440+ aggregate.best .elapsed_ns () / std::size (url_examples);
441+ state.counters [" cycle/byte" ] = aggregate.best .cycles () / url_examples_bytes;
442+ }
443+ (void )success;
444+ (void )href_size;
445+
446+ state.counters [" time/byte" ] = benchmark::Counter (
447+ url_examples_bytes, benchmark::Counter::kIsIterationInvariantRate |
448+ benchmark::Counter::kInvert );
449+ state.counters [" time/url" ] = benchmark::Counter (
450+ std::size (url_examples), benchmark::Counter::kIsIterationInvariantRate |
451+ benchmark::Counter::kInvert );
452+ state.counters [" speed" ] = benchmark::Counter (
453+ url_examples_bytes, benchmark::Counter::kIsIterationInvariantRate );
454+ state.counters [" url/s" ] = benchmark::Counter (
455+ std::size (url_examples), benchmark::Counter::kIsIterationInvariantRate );
456+ }
457+
458+ BENCHMARK (BasicBench_ZURI);
459+ #endif // ADA_ZURI_ENABLED
460+
370461#if ADA_VARIOUS_COMPETITION_ENABLED
371462static void BasicBench_uriparser_just_parse (benchmark::State& state) {
372463 // volatile to prevent optimizations.
@@ -658,6 +749,13 @@ int main(int argc, char** argv) {
658749 " Boost URL follows RFC3986, not whatwg/url" );
659750 size_t boost_bad_url = count_boosturl_invalid ();
660751#endif
752+ #if ADA_ZURI_ENABLED
753+ benchmark::AddCustomContext (" zuri spec" ,
754+ " Zuri follows RFC3986, not whatwg/url" );
755+ size_t zuri_bad_url = count_zuri_invalid ();
756+ #else
757+ benchmark::AddCustomContext (" zuri " , " OMITTED" );
758+ #endif
661759#if (__APPLE__ && __aarch64__) || defined(__linux__)
662760 if (!collector.has_events ()) {
663761 benchmark::AddCustomContext (" performance counters" ,
@@ -702,6 +800,10 @@ int main(int argc, char** argv) {
702800#if ADA_BOOST_ENABLED
703801 badcounts << " boost-url---count of bad URLs " << std::to_string (boost_bad_url)
704802 << " \n " ;
803+ #endif
804+ #if ADA_ZURI_ENABLED
805+ badcounts << " zuri---count of bad URLs " << std::to_string (zuri_bad_url)
806+ << " \n " ;
705807#endif
706808 badcounts << " -------------------------------\n " ;
707809 benchmark::AddCustomContext (" bad urls" , badcounts.str ());
@@ -713,4 +815,4 @@ int main(int argc, char** argv) {
713815 benchmark::Initialize (&argc, argv);
714816 benchmark::RunSpecifiedBenchmarks ();
715817 benchmark::Shutdown ();
716- }
818+ }
0 commit comments