1- #include " counters/event_counter .h"
1+ #include " counters/bench .h"
22#include " fast_float/fast_float.h"
33#include < charconv>
44#include < cstdint>
88#include < random>
99#include < atomic>
1010#include < string>
11- event_collector collector;
12-
13- template <class function_type >
14- event_aggregate bench (const function_type &function, size_t min_repeat = 10 ,
15- size_t min_time_ns = 1000000000 ,
16- size_t max_repeat = 1000000 ) {
17- event_aggregate aggregate{};
18- size_t N = min_repeat;
19- if (N == 0 ) {
20- N = 1 ;
21- }
22- for (size_t i = 0 ; i < N; i++) {
23- std::atomic_thread_fence (std::memory_order_acquire);
24- collector.start ();
25- function ();
26- std::atomic_thread_fence (std::memory_order_release);
27- event_count allocate_count = collector.end ();
28- aggregate << allocate_count;
29- if ((i + 1 == N) && (aggregate.total_elapsed_ns () < min_time_ns) &&
30- (N < max_repeat)) {
31- N *= 10 ;
32- }
33- }
34- return aggregate;
35- }
3611
3712void pretty_print (size_t volume, size_t bytes, std::string name,
38- event_aggregate agg) {
13+ counters:: event_aggregate agg) {
3914 printf (" %-40s : " , name.c_str ());
4015 printf (" %5.2f GB/s " , bytes / agg.fastest_elapsed_ns ());
4116 printf (" %5.1f Ma/s " , volume * 1000.0 / agg.fastest_elapsed_ns ());
4217 printf (" %5.2f ns/d " , agg.fastest_elapsed_ns () / volume);
43- if (collector .has_events ()) {
18+ if (counters::event_collector () .has_events ()) {
4419 printf (" %5.2f GHz " , agg.fastest_cycles () / agg.fastest_elapsed_ns ());
4520 printf (" %5.2f c/d " , agg.fastest_cycles () / volume);
4621 printf (" %5.2f i/d " , agg.fastest_instructions () / volume);
@@ -158,7 +133,7 @@ int main() {
158133
159134 uint32_t sink = 0 ;
160135
161- pretty_print (volume, bytes, " parse_ip_std_fromchars" , bench ([&]() {
136+ pretty_print (volume, bytes, " parse_ip_std_fromchars" , counters:: bench ([&]() {
162137 const char *p = buf.data ();
163138 const char *pend = buf.data () + bytes;
164139 uint32_t sum = 0 ;
@@ -171,7 +146,7 @@ int main() {
171146 sink += sum;
172147 }));
173148
174- pretty_print (volume, bytes, " parse_ip_fastfloat" , bench ([&]() {
149+ pretty_print (volume, bytes, " parse_ip_fastfloat" , counters:: bench ([&]() {
175150 const char *p = buf.data ();
176151 const char *pend = buf.data () + bytes;
177152 uint32_t sum = 0 ;
0 commit comments