@@ -89,6 +89,66 @@ auto BasicBench_AdaURL_aggregator_href =
89
89
BasicBench_AdaURL<PARSE_AND_HREF, ada::url_aggregator>;
90
90
BENCHMARK (BasicBench_AdaURL_aggregator_href);
91
91
92
+ static void BasicBench_AdaURL_CanParse (benchmark::State& state) {
93
+ // volatile to prevent optimizations.
94
+ volatile size_t success = 0 ;
95
+
96
+ for (auto _ : state) {
97
+ for (std::string& url_string : url_examples) {
98
+ bool can_parse = ada::can_parse (url_string);
99
+ if (can_parse) {
100
+ success++;
101
+ }
102
+ }
103
+ }
104
+ if (collector.has_events ()) {
105
+ event_aggregate aggregate{};
106
+ for (size_t i = 0 ; i < N; i++) {
107
+ std::atomic_thread_fence (std::memory_order_acquire);
108
+ collector.start ();
109
+ for (std::string& url_string : url_examples) {
110
+ bool can_parse = ada::can_parse (url_string);
111
+ if (can_parse) {
112
+ success++;
113
+ }
114
+ }
115
+ std::atomic_thread_fence (std::memory_order_release);
116
+ event_count allocate_count = collector.end ();
117
+ aggregate << allocate_count;
118
+ }
119
+ state.counters [" cycles/url" ] =
120
+ aggregate.best .cycles () / std::size (url_examples);
121
+ state.counters [" instructions/url" ] =
122
+ aggregate.best .instructions () / std::size (url_examples);
123
+ state.counters [" instructions/cycle" ] =
124
+ aggregate.best .instructions () / aggregate.best .cycles ();
125
+ state.counters [" instructions/byte" ] =
126
+ aggregate.best .instructions () / url_examples_bytes;
127
+ state.counters [" instructions/ns" ] =
128
+ aggregate.best .instructions () / aggregate.best .elapsed_ns ();
129
+ state.counters [" GHz" ] =
130
+ aggregate.best .cycles () / aggregate.best .elapsed_ns ();
131
+ state.counters [" ns/url" ] =
132
+ aggregate.best .elapsed_ns () / std::size (url_examples);
133
+ state.counters [" cycle/byte" ] = aggregate.best .cycles () / url_examples_bytes;
134
+ }
135
+ (void )success;
136
+ state.counters [" time/byte" ] = benchmark::Counter (
137
+ url_examples_bytes, benchmark::Counter::kIsIterationInvariantRate |
138
+ benchmark::Counter::kInvert );
139
+ state.counters [" time/url" ] =
140
+ benchmark::Counter (double (std::size (url_examples)),
141
+ benchmark::Counter::kIsIterationInvariantRate |
142
+ benchmark::Counter::kInvert );
143
+ state.counters [" speed" ] = benchmark::Counter (
144
+ url_examples_bytes, benchmark::Counter::kIsIterationInvariantRate );
145
+ state.counters [" url/s" ] =
146
+ benchmark::Counter (double (std::size (url_examples)),
147
+ benchmark::Counter::kIsIterationInvariantRate );
148
+ }
149
+
150
+ BENCHMARK (BasicBench_AdaURL_CanParse);
151
+
92
152
#if ADA_url_whatwg_ENABLED
93
153
size_t count_whatwg_invalid () {
94
154
size_t how_many = 0 ;
0 commit comments