11 #ifndef INCLUDED_BENCHMARK_COMMON
12 #define INCLUDED_BENCHMARK_COMMON
15 #include <spdlog/tweakme.h>
17 #include <spdlog/fmt/fmt.h>
18 #include <string_view>
24 template <
typename functor>
25 [[nodiscard]]
auto benchmark(functor test,
size_t block_size)
27 using namespace std::chrono;
28 std::vector<float> outp(2 * block_size);
29 float* output = outp.data();
30 float *x = &output[0], *y = &output[block_size];
33 memset(output, 0, 2 * block_size *
sizeof(
float));
35 auto before = high_resolution_clock::now();
40 auto after = high_resolution_clock::now();
42 auto dur = duration_cast<duration<double, std::ratio<1, 1>>>(after - before);
45 template <
typename dur_t>
51 auto dur_s = std::chrono::duration_cast<std::chrono::duration<double>>(dur);
52 return fmt::format(FMT_STRING(
"{:<18} time: {:<8.4e} s throughput: {:>6.3e} it/s"),
55 static_cast<double>(iterations) / dur_s.count());
auto format_duration(std::string_view name, dur_t dur, size_t iterations, size_t block_size)
Definition: benchmark_common.h:46
auto benchmark(functor test, size_t block_size)
Definition: benchmark_common.h:25
fmt::format_context::iterator format(const gr::io_signature &iosig, format_context &ctx) const