void benchmark()

in benchmark/include/spotify/json/benchmark/benchmark.hpp [23:40]


void benchmark(const char *name, const size_t count, const test_fn &test) {
  using namespace std::chrono;
  const auto before = high_resolution_clock::now();
  for (unsigned i = 0; i < count; i++) {
    test();
  }
  const auto after = high_resolution_clock::now();

  const auto duration = (after - before);
  const auto duration_ms = duration_cast<milliseconds>(duration).count();
  const auto duration_us = duration_cast<microseconds>(duration).count();
  const auto duration_us_avg = (duration_us / static_cast<double>(count));
  std::cerr
      << name << ": "
      << duration_us_avg << " us avg (" << count << " runs), "
      << duration_ms << " ms total"
      << std::endl;
}