Skip to content

Commit

Permalink
use chrono for walltime since it is thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWF committed Sep 2, 2016
1 parent 9cd8a88 commit ebae4a7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
19 changes: 0 additions & 19 deletions src/walltime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,6 @@ namespace walltime {

namespace {

#if defined(HAVE_STEADY_CLOCK)
template <bool HighResIsSteady = std::chrono::high_resolution_clock::is_steady>
struct ChooseSteadyClock {
typedef std::chrono::high_resolution_clock type;
};

template <>
struct ChooseSteadyClock<false> {
typedef std::chrono::steady_clock type;
};
#endif

struct ChooseClockType {
#if defined(HAVE_STEADY_CLOCK)
typedef ChooseSteadyClock<>::type type;
#else
typedef std::chrono::high_resolution_clock type;
#endif
};

class WallTimeImp
{
Expand Down
31 changes: 31 additions & 0 deletions src/walltime.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
#ifndef BENCHMARK_WALLTIME_H_
#define BENCHMARK_WALLTIME_H_

#include "internal_macros.h"

#include <chrono>
#include <string>

namespace benchmark {
typedef double WallTime;

namespace walltime {

#if defined(HAVE_STEADY_CLOCK)
template <bool HighResIsSteady = std::chrono::high_resolution_clock::is_steady>
struct ChooseSteadyClock {
typedef std::chrono::high_resolution_clock type;
};

template <>
struct ChooseSteadyClock<false> {
typedef std::chrono::steady_clock type;
};
#endif

struct ChooseClockType {
#if defined(HAVE_STEADY_CLOCK)
typedef ChooseSteadyClock<>::type type;
#else
typedef std::chrono::high_resolution_clock type;
#endif
};

inline double ChronoClockNow() {
typedef ChooseClockType::type ClockType;
using FpSeconds =
std::chrono::duration<double, std::chrono::seconds::period>;
return FpSeconds(ClockType::now().time_since_epoch()).count();
}

WallTime Now();
} // end namespace walltime

Expand Down

0 comments on commit ebae4a7

Please sign in to comment.