diff --git a/benchmarks/benchmark.cpp b/benchmarks/benchmark.cpp index 5090752..1e06e30 100644 --- a/benchmarks/benchmark.cpp +++ b/benchmarks/benchmark.cpp @@ -27,59 +27,39 @@ #include "fast_float/fast_float.h" -#ifdef USING_COUNTERS -event_collector collector{}; -#else -std::chrono::high_resolution_clock::time_point t1, t2; -#endif - template -Value findmax_fastfloat(std::vector> &s, -#ifdef USING_COUNTERS - std::vector &aggregate -#else - std::chrono::nanoseconds &time -#endif -) { +Value findmax_fastfloat(std::vector> &s) { Value answer = 0; Value x = 0; -#ifdef USING_COUNTERS - collector.start(); -#endif for (auto &st : s) { -#ifndef USING_COUNTERS - t1 = std::chrono::high_resolution_clock::now(); -#endif auto [p, ec] = fast_float::from_chars(st.data(), st.data() + st.size(), x); -#ifndef USING_COUNTERS - t2 = std::chrono::high_resolution_clock::now(); - time += std::chrono::duration_cast(t2 - t1); -#endif if (p == st.data()) { throw std::runtime_error("bug in findmax_fastfloat"); } answer = answer > x ? answer : x; } -#ifdef USING_COUNTERS - aggregate.push_back(collector.end()); -#endif return answer; } #ifdef USING_COUNTERS + +event_collector collector{}; + template std::vector time_it_ns(std::vector> &lines, T const &function, size_t repeat) { std::vector aggregate; + collector.start(); bool printed_bug = false; for (size_t i = 0; i < repeat; i++) { - double ts = function(lines, aggregate); + double ts = function(lines); if (ts == 0 && !printed_bug) { printf("bug\n"); printed_bug = true; } + aggregate.push_back(collector.end()); } return aggregate; } @@ -148,18 +128,20 @@ template std::pair time_it_ns(std::vector> &lines, T const &function, size_t repeat) { + std::chrono::high_resolution_clock::time_point t1, t2; double average = 0; double min_value = DBL_MAX; bool printed_bug = false; for (size_t i = 0; i < repeat; i++) { - std::chrono::nanoseconds time{}; - const auto ts = function(lines, time); + t1 = std::chrono::high_resolution_clock::now(); + const auto ts = function(lines); if (ts == 0 && !printed_bug) { printf("bug\n"); printed_bug = true; } + t2 = std::chrono::high_resolution_clock::now(); double dif = - std::chrono::duration_cast(time).count(); + std::chrono::duration_cast(t2 - t1).count(); average += dif; min_value = min_value < dif ? min_value : dif; }