25#if !defined(LOOS_TIMER_HPP)
33#include <sys/resource.h>
34#include <boost/format.hpp>
36#include <loos_defs.hpp>
44 double currentTime(
void)
const {
47 int i = gettimeofday(&tv, 0);
49 throw(std::runtime_error(
"Error in gettimeofday()"));
50 return(
static_cast<double>(tv.tv_sec) +
static_cast<double>(tv.tv_usec) * 1e-6);
57 double currentTime(
void)
const {
59 int i = getrusage(RUSAGE_SELF, &ru);
61 throw(std::runtime_error(
"Error in getrusage()"));
62 return(
static_cast<double>(ru.ru_utime.tv_sec) +
static_cast<double>(ru.ru_utime.tv_usec) * 1e-6);
79 template<
class TimerType = WallTimer>
80 class Timer :
public TimerType {
82 Timer() : t0(0), t1(0), avg(0), lapt(0), n(0), running(
false) { }
86 lapt = t0 = TimerType::currentTime();
95 t1 = TimerType::currentTime();
109 double elapsed(
void)
const {
return( running ? TimerType::currentTime() - t0 : t1 - t0 ); }
122 double t = TimerType::currentTime();
123 double lt = t - lapt;
133 double t0, t1, avg, lapt;
139 std::ostream& operator<<(std::ostream& os,
const Timer<T>& t) {
141 os <<
"Elapsed time " << s;
Class for tracking time.
Definition loos_timer.hpp:80
void start(void)
Starts the timer.
Definition loos_timer.hpp:85
double stop(void)
Stops the timer.
Definition loos_timer.hpp:94
double elapsed(void) const
Return the elapsed time.
Definition loos_timer.hpp:109
double averageLapTime(void)
Return the current average lap-time...
Definition loos_timer.hpp:130
double lap(void)
Returns the current lap time.
Definition loos_timer.hpp:118
Policy class for tracking only user process time.
Definition loos_timer.hpp:55
Policy class for tracking wall-time.
Definition loos_timer.hpp:42
Namespace for most things not already encapsulated within a class.
Definition version.cpp:3
std::string timeAsString(const double t, const uint precision)
Convert t (seconds) into a string, converting to hours and minutes as necessary.
Definition utils.cpp:203