From 0aec5003b3160ffbd0189bc9561f14cb4ab5c10b Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Wed, 1 Oct 2014 11:38:08 +0200 Subject: [PATCH] Use std::chrono instead of boost::chrono in benchmarks. This reduces the external dependencies and fixes a bug where a duration was reported in microseconds instead of milliseconds on some systems. --- benchmark/bench_framework.hpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/benchmark/bench_framework.hpp b/benchmark/bench_framework.hpp index 06f8dfd56..f2afc4857 100644 --- a/benchmark/bench_framework.hpp +++ b/benchmark/bench_framework.hpp @@ -5,17 +5,14 @@ #include #include -// boost -#define BOOST_CHRONO_HEADER_ONLY -#include -#include - // stl +#include +#include #include +#include +#include #include #include -#include -#include namespace benchmark { @@ -88,8 +85,8 @@ int run(T const& test_runner, std::string const& name) std::clog << "test did not validate: " << name << "\n"; return -1; } - boost::chrono::process_cpu_clock::time_point start; - boost::chrono::process_cpu_clock::duration elapsed; + std::chrono::high_resolution_clock::time_point start; + std::chrono::high_resolution_clock::duration elapsed; std::stringstream s; s << name << ":" << std::setw(45 - (int)s.tellp()) << std::right @@ -104,18 +101,18 @@ int run(T const& test_runner, std::string const& name) { tg.emplace_back(new std::thread(test_runner)); } - start = boost::chrono::process_cpu_clock::now(); + start = std::chrono::high_resolution_clock::now(); std::for_each(tg.begin(), tg.end(), [](value_type & t) {if (t->joinable()) t->join();}); - elapsed = boost::chrono::process_cpu_clock::now() - start; + elapsed = std::chrono::high_resolution_clock::now() - start; } else { - start = boost::chrono::process_cpu_clock::now(); + start = std::chrono::high_resolution_clock::now(); test_runner(); - elapsed = boost::chrono::process_cpu_clock::now() - start; + elapsed = std::chrono::high_resolution_clock::now() - start; } s << std::setw(65 - (int)s.tellp()) << std::right - << boost::chrono::duration_cast(elapsed) << "\n"; + << std::chrono::duration_cast(elapsed).count() << " milliseconds\n"; std::clog << s.str(); return 0; }