Skip to content

Commit 6952ffe

Browse files
committed
lint
1 parent 0fa058e commit 6952ffe

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

benchmarks/bench_ip.cpp

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,31 @@
66
#include <cstdlib>
77
#include <cstring>
88
#include <random>
9-
#include <atomic>
9+
#include <atomic>
1010
event_collector collector;
1111

12-
template <class function_type>
13-
event_aggregate bench(const function_type& function, size_t min_repeat = 10, size_t min_time_ns = 1000000000, size_t max_repeat = 1000000) {
14-
event_aggregate aggregate{};
15-
size_t N = min_repeat;
16-
if(N == 0) { N = 1; }
17-
for (size_t i = 0; i < N; i++) {
18-
std::atomic_thread_fence(std::memory_order_acquire);
19-
collector.start();
20-
function();
21-
std::atomic_thread_fence(std::memory_order_release);
22-
event_count allocate_count = collector.end();
23-
aggregate << allocate_count;
24-
if((i+1 == N) && (aggregate.total_elapsed_ns() < min_time_ns) && (N<max_repeat)) {
25-
N *= 10;
26-
}
12+
template <class function_type>
13+
event_aggregate bench(const function_type &function, size_t min_repeat = 10,
14+
size_t min_time_ns = 1000000000,
15+
size_t max_repeat = 1000000) {
16+
event_aggregate aggregate{};
17+
size_t N = min_repeat;
18+
if (N == 0) {
19+
N = 1;
20+
}
21+
for (size_t i = 0; i < N; i++) {
22+
std::atomic_thread_fence(std::memory_order_acquire);
23+
collector.start();
24+
function();
25+
std::atomic_thread_fence(std::memory_order_release);
26+
event_count allocate_count = collector.end();
27+
aggregate << allocate_count;
28+
if ((i + 1 == N) && (aggregate.total_elapsed_ns() < min_time_ns) &&
29+
(N < max_repeat)) {
30+
N *= 10;
2731
}
28-
return aggregate;
32+
}
33+
return aggregate;
2934
}
3035

3136
void pretty_print(size_t volume, size_t bytes, std::string name,
@@ -45,7 +50,7 @@ void pretty_print(size_t volume, size_t bytes, std::string name,
4550
printf("\n");
4651
}
4752

48-
int parse_u8_fastswar(const char *&p, const char *pend, uint8_t *out) {
53+
int parse_u8_fastfloat(const char *&p, const char *pend, uint8_t *out) {
4954
if (p == pend)
5055
return 0;
5156
auto r = fast_float::from_chars(p, pend, *out);
@@ -142,7 +147,7 @@ int main() {
142147
}
143148
p = start;
144149
pend = end;
145-
ok = parse_ip_line(p, pend, sum, parse_u8_fastswar);
150+
ok = parse_ip_line(p, pend, sum, parse_u8_fastfloat);
146151
if (!ok) {
147152
std::fprintf(stderr, "fastswar parse failed at line %zu\n", i);
148153
std::abort();
@@ -152,7 +157,7 @@ int main() {
152157

153158
uint32_t sink = 0;
154159

155-
pretty_print(volume, bytes, "parse_ip_fromchars", bench([&]() {
160+
pretty_print(volume, bytes, "parse_ip_std_fromchars", bench([&]() {
156161
const char *p = buf.data();
157162
const char *pend = buf.data() + bytes;
158163
uint32_t sum = 0;
@@ -165,13 +170,13 @@ int main() {
165170
sink += sum;
166171
}));
167172

168-
pretty_print(volume, bytes, "parse_ip_fastswar", bench([&]() {
173+
pretty_print(volume, bytes, "parse_ip_fastfloat", bench([&]() {
169174
const char *p = buf.data();
170175
const char *pend = buf.data() + bytes;
171176
uint32_t sum = 0;
172177
int ok = 0;
173178
for (size_t i = 0; i < N; ++i) {
174-
ok = parse_ip_line(p, pend, sum, parse_u8_fastswar);
179+
ok = parse_ip_line(p, pend, sum, parse_u8_fastfloat);
175180
if (!ok)
176181
std::abort();
177182
}

0 commit comments

Comments
 (0)