6 #ifndef TIMER_USE_STD_CLOCK
8 #include <sys/resource.h>
60 isRunning_ = startImmediately;
68 storedLastElapsed_ = 0.0;
103 return storedLastElapsed_;
114 sumElapsed_ += storedLastElapsed_;
125 double storedLastElapsed_;
128 #ifdef TIMER_USE_STD_CLOCK
131 cstart = std::clock();
134 double rawElapsed ()
const throw (TimerError)
136 return (std::clock()-cstart) /
static_cast<double>(CLOCKS_PER_SEC);
141 void rawReset() throw (TimerError)
144 if (getrusage(RUSAGE_SELF, &ru))
146 cstart = ru.ru_utime;
149 double rawElapsed ()
const throw (TimerError)
152 if (getrusage(RUSAGE_SELF, &ru))
154 return 1.0 * (ru.ru_utime.tv_sec - cstart.tv_sec) + (ru.ru_utime.tv_usec - cstart.tv_usec) / (1000.0 * 1000.0);
157 struct timeval cstart;
void start()
Start the timer and continue measurement if it is not running. Otherwise do nothing.
Definition: timer.hh:74
A few common exception classes.
double stop()
Stop the timer and return elapsed().
Definition: timer.hh:108
A simple stop watch.
Definition: timer.hh:50
double lastElapsed() const
Get elapsed user-time from last start until now/last stop in seconds.
Definition: timer.hh:96
Exception thrown by the Timer class
Definition: timer.hh:32
Timer(bool startImmediately=true)
A new timer, create and reset.
Definition: timer.hh:58
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
Default exception class for OS errors.
Definition: exceptions.hh:297
void reset()
Reset timer while keeping the running/stopped state.
Definition: timer.hh:65
double elapsed() const
Get elapsed user-time from last reset until now/last stop in seconds.
Definition: timer.hh:85