mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-24 12:34:53 +08:00
lint
This commit is contained in:
parent
0fa058eebb
commit
6952ffeec0
@ -6,26 +6,31 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
event_collector collector;
|
event_collector collector;
|
||||||
|
|
||||||
template <class function_type>
|
template <class function_type>
|
||||||
event_aggregate bench(const function_type& function, size_t min_repeat = 10, size_t min_time_ns = 1000000000, size_t max_repeat = 1000000) {
|
event_aggregate bench(const function_type &function, size_t min_repeat = 10,
|
||||||
event_aggregate aggregate{};
|
size_t min_time_ns = 1000000000,
|
||||||
size_t N = min_repeat;
|
size_t max_repeat = 1000000) {
|
||||||
if(N == 0) { N = 1; }
|
event_aggregate aggregate{};
|
||||||
for (size_t i = 0; i < N; i++) {
|
size_t N = min_repeat;
|
||||||
std::atomic_thread_fence(std::memory_order_acquire);
|
if (N == 0) {
|
||||||
collector.start();
|
N = 1;
|
||||||
function();
|
}
|
||||||
std::atomic_thread_fence(std::memory_order_release);
|
for (size_t i = 0; i < N; i++) {
|
||||||
event_count allocate_count = collector.end();
|
std::atomic_thread_fence(std::memory_order_acquire);
|
||||||
aggregate << allocate_count;
|
collector.start();
|
||||||
if((i+1 == N) && (aggregate.total_elapsed_ns() < min_time_ns) && (N<max_repeat)) {
|
function();
|
||||||
N *= 10;
|
std::atomic_thread_fence(std::memory_order_release);
|
||||||
}
|
event_count allocate_count = collector.end();
|
||||||
|
aggregate << allocate_count;
|
||||||
|
if ((i + 1 == N) && (aggregate.total_elapsed_ns() < min_time_ns) &&
|
||||||
|
(N < max_repeat)) {
|
||||||
|
N *= 10;
|
||||||
}
|
}
|
||||||
return aggregate;
|
}
|
||||||
|
return aggregate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pretty_print(size_t volume, size_t bytes, std::string name,
|
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,
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_u8_fastswar(const char *&p, const char *pend, uint8_t *out) {
|
int parse_u8_fastfloat(const char *&p, const char *pend, uint8_t *out) {
|
||||||
if (p == pend)
|
if (p == pend)
|
||||||
return 0;
|
return 0;
|
||||||
auto r = fast_float::from_chars(p, pend, *out);
|
auto r = fast_float::from_chars(p, pend, *out);
|
||||||
@ -142,7 +147,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
p = start;
|
p = start;
|
||||||
pend = end;
|
pend = end;
|
||||||
ok = parse_ip_line(p, pend, sum, parse_u8_fastswar);
|
ok = parse_ip_line(p, pend, sum, parse_u8_fastfloat);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
std::fprintf(stderr, "fastswar parse failed at line %zu\n", i);
|
std::fprintf(stderr, "fastswar parse failed at line %zu\n", i);
|
||||||
std::abort();
|
std::abort();
|
||||||
@ -152,7 +157,7 @@ int main() {
|
|||||||
|
|
||||||
uint32_t sink = 0;
|
uint32_t sink = 0;
|
||||||
|
|
||||||
pretty_print(volume, bytes, "parse_ip_fromchars", bench([&]() {
|
pretty_print(volume, bytes, "parse_ip_std_fromchars", bench([&]() {
|
||||||
const char *p = buf.data();
|
const char *p = buf.data();
|
||||||
const char *pend = buf.data() + bytes;
|
const char *pend = buf.data() + bytes;
|
||||||
uint32_t sum = 0;
|
uint32_t sum = 0;
|
||||||
@ -165,13 +170,13 @@ int main() {
|
|||||||
sink += sum;
|
sink += sum;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
pretty_print(volume, bytes, "parse_ip_fastswar", bench([&]() {
|
pretty_print(volume, bytes, "parse_ip_fastfloat", bench([&]() {
|
||||||
const char *p = buf.data();
|
const char *p = buf.data();
|
||||||
const char *pend = buf.data() + bytes;
|
const char *pend = buf.data() + bytes;
|
||||||
uint32_t sum = 0;
|
uint32_t sum = 0;
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
for (size_t i = 0; i < N; ++i) {
|
for (size_t i = 0; i < N; ++i) {
|
||||||
ok = parse_ip_line(p, pend, sum, parse_u8_fastswar);
|
ok = parse_ip_line(p, pend, sum, parse_u8_fastfloat);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user