diff options
Diffstat (limited to 'src/core/timer.cc')
-rw-r--r-- | src/core/timer.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/core/timer.cc b/src/core/timer.cc new file mode 100644 index 0000000..e5a808e --- /dev/null +++ b/src/core/timer.cc @@ -0,0 +1,41 @@ +/* + core/timer.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#include "core/timer.h" + +#include <unistd.h> +#include <iostream> + +namespace core { + +Timer::Timer() +{ + gettimeofday(&this->timer_tick, &this->timer_tz); + this->timer_elapsed = 0; +} + +Timer::~Timer() +{ +} + +void Timer::mark() +{ + gettimeofday(&timer_tick, &timer_tz); +} + +float Timer::elapsed() +{ + struct timeval tick; + struct timezone tick_tz; + + gettimeofday(&tick, &tick_tz); + + // calculate elapsed time in 10^-6 seconds + long delta = (tick.tv_sec - timer_tick.tv_sec) * 1000000 + (tick.tv_usec - timer_tick.tv_usec); + return( (float) delta / 1000000.0f); +} + +} |