16 #ifndef FOXXLL_COMMON_TIMER_HEADER 17 #define FOXXLL_COMMON_TIMER_HEADER 27 #include <foxxll/config.hpp> 38 return static_cast<double>(
39 std::chrono::duration_cast<std::chrono::microseconds>(
40 std::chrono::steady_clock::now().time_since_epoch()
75 explicit timer(
bool start_immediately =
false)
76 : running(false), accumulated(0), last_clock(0)
78 if (start_immediately)
start();
94 std::unique_lock<std::mutex> lock(mutex_accumulated);
101 std::unique_lock<std::mutex> lock(mutex_accumulated);
109 std::unique_lock<std::mutex> lock(mutex_accumulated);
112 return (accumulated +
timestamp() - last_clock) * 1000.;
114 return (accumulated * 1000.);
122 std::unique_lock<std::mutex> lock(mutex_accumulated);
125 return (accumulated +
delta) * 1000000.;
127 return (accumulated * 1000000.);
135 std::unique_lock<std::mutex> lock(mutex_accumulated);
138 return (accumulated +
delta);
140 return (accumulated);
147 std::unique_lock<std::mutex> lock(mutex_accumulated);
149 accumulated +=
delta;
156 return os << t.
seconds() <<
's';
192 return std::numeric_limits<double>::quiet_NaN();
198 return std::numeric_limits<double>::quiet_NaN();
204 return std::numeric_limits<double>::quiet_NaN();
216 return os << t.
seconds() <<
's';
239 : m_message(message),
252 <<
" after " << m_timer.
seconds() <<
" seconds";
255 double bps =
static_cast<double>(m_bytes) / m_timer.
seconds();
260 <<
" after " << m_timer.
seconds() <<
" seconds. " 277 #endif // !FOXXLL_COMMON_TIMER_HEADER
Class fake_timer is a drop-in replacement for timer, which does nothing.
timer(bool start_immediately=false)
initialize and optionally immediately start the timer
static const bool is_real
boolean indicating that this class does real timing
double accumulated
total accumulated time in seconds.
Simple scoped timer, which takes a text message and prints the duration until the scope is destroyed...
double mseconds() const
return currently accumulated time in milliseconds
static constexpr double delta
~scoped_print_timer()
on destruction: tell the time
foxxll::timer m_timer
timer
static double timestamp()
Returns number of seconds since the epoch, high resolution.
const foxxll::timer & timer() const
constant access to enclosed timer
static double timestamp()
return current timestamp
uint64_t m_bytes
bytes processed
friend std::ostream & operator<<(std::ostream &os, const timer &t)
direct <<-operator for ostream. Can be used for printing with std::cout.
double mseconds() const
return currently accumulated time in milliseconds
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
std::string m_message
message
double seconds() const
return currently accumulated time in seconds (as double)
Class timer is a simple stop watch timer.
static const size_t bytes
number of bytes in uint_pair
double useconds() const
return currently accumulated time in microseconds
double seconds() const
return currently accumulated time in seconds (as double)
bool running
boolean whether the stopwatch timer is currently running
scoped_print_timer(const std::string &message, const uint64_t bytes=0)
save message and start timer
fake_timer(bool=false)
initialize and optionally immediately start the timer
double last_clock
last start time of the stopwatch
timer & operator+=(const timer &tm)
accumulate elapsed time from another timer
double useconds() const
return currently accumulated time in microseconds
void reset()
return accumulated time
void reset()
return accumulated time
std::mutex mutex_accumulated
guard accumulated
std::string format_iec_units(uint64_t number, int precision=3)
Format number as something like 1 TiB.