chronos.cpp 608 Bytes
Newer Older
Luis Peñaranda's avatar
Luis Peñaranda committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#ifdef _WIN32
#include <windows.h>
#else
#include <ctime>
#include <sys/time.h>
#endif

#include "chronos.h"

Chronos::
Chronos() { 
    reset(); 
}

void 
Chronos::
reset(void) { 
    m_reset = time(); 
}

double 
Chronos::
elapsed(void) { 
    return time() - m_reset; 
}

double 
Chronos::time(void) {
#ifdef _WIN32
    LARGE_INTEGER counter, freq;
    QueryPerformanceCounter(&counter);
    QueryPerformanceFrequency(&freq);
    return (1.0*counter.QuadPart)/(1.0*freq.QuadPart);
#else
    struct timeval v;
    gettimeofday(&v, (struct timezone *) NULL);
    return v.tv_sec + v.tv_usec/1.0e6;
#endif
}