|
13 | 13 | #include "user_profile.hpp" |
14 | 14 | #include "custom_serializer.h" |
15 | 15 | #include "nlohmann_user_profile.hpp" |
| 16 | +#include "benchmark_helper.hpp" |
| 17 | + |
16 | 18 | #if SIMDJSON_BENCH_CPP_REFLECT |
17 | 19 | #include "benchmark_reflect_serialization.hpp" |
18 | 20 | #endif |
@@ -102,46 +104,6 @@ User generate_random_user() { |
102 | 104 | return user; |
103 | 105 | } |
104 | 106 |
|
105 | | -event_collector collector; |
106 | | - |
107 | | -template <class function_type> |
108 | | -event_aggregate bench(const function_type &function, size_t min_repeat = 10, |
109 | | - size_t min_time_ns = 1000000000, |
110 | | - size_t max_repeat = 100) { |
111 | | - event_aggregate aggregate{}; |
112 | | - size_t N = min_repeat; |
113 | | - if (N == 0) { |
114 | | - N = 1; |
115 | | - } |
116 | | - for (size_t i = 0; i < N; i++) { |
117 | | - std::atomic_thread_fence(std::memory_order_acquire); |
118 | | - collector.start(); |
119 | | - function(); |
120 | | - std::atomic_thread_fence(std::memory_order_release); |
121 | | - event_count allocate_count = collector.end(); |
122 | | - aggregate << allocate_count; |
123 | | - if ((i + 1 == N) && (aggregate.total_elapsed_ns() < min_time_ns) && |
124 | | - (N < max_repeat)) { |
125 | | - N *= 10; |
126 | | - } |
127 | | - } |
128 | | - return aggregate; |
129 | | -} |
130 | | - |
131 | | -// Source of the 2 functions below: |
132 | | -// https://github.com/simdutf/simdutf/blob/master/benchmarks/base64/benchmark_base64.cpp |
133 | | -void pretty_print(size_t strings, size_t bytes, std::string name, event_aggregate agg) { |
134 | | - printf("%-60s : ", name.c_str()); |
135 | | - printf(" %5.2f MB/s ", bytes * 1000 / agg.elapsed_ns()); |
136 | | - printf(" %5.2f Ms/s ", strings * 1000 / agg.elapsed_ns()); |
137 | | - if (collector.has_events()) { |
138 | | - printf(" %5.2f GHz ", agg.cycles() / agg.elapsed_ns()); |
139 | | - printf(" %5.2f c/b ", agg.cycles() / bytes); |
140 | | - printf(" %5.2f i/b ", agg.instructions() / bytes); |
141 | | - printf(" %5.2f i/c ", agg.instructions() / agg.cycles()); |
142 | | - } |
143 | | - printf("\n"); |
144 | | -} |
145 | 107 |
|
146 | 108 | void bench_custom(std::vector<User> &data) { |
147 | 109 | size_t volume = std::accumulate(data.begin(), data.end(), size_t(0), [](size_t a, const User &b) { return a + sizeof(b); }); |
|
0 commit comments