File: gstopwatch.cpp

package info (click to toggle)
libgclib 0.11.10%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 972 kB
  • sloc: cpp: 18,275; makefile: 58; sh: 21
file content (44 lines) | stat: -rw-r--r-- 931 bytes parent folder | download | duplicates (2)
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
40
41
42
43
44
#include "gstopwatch.h"

#ifdef _WIN32
double GStopWatch::LIToSecs( LARGE_INTEGER & L) {
  return ((double)L.QuadPart /(double)frequency.QuadPart);
}

GStopWatch::GStopWatch(){
  timer.start.QuadPart=0;
  timer.stop.QuadPart=0;  
  QueryPerformanceFrequency( &frequency );
}

void GStopWatch::startTimer( ) {
    QueryPerformanceCounter(&timer.start);
}

void GStopWatch::stopTimer( ) {
    QueryPerformanceCounter(&timer.stop);
}


double GStopWatch::getElapsedTime() {
  LARGE_INTEGER time;
  time.QuadPart = timer.stop.QuadPart - timer.start.QuadPart;
    return LIToSecs( time) ;
}
#else
//Linux code:
void GStopWatch::startTimer( ) {
  gettimeofday(&(timer.start),NULL);
}

void GStopWatch::stopTimer( ) {
  gettimeofday(&(timer.stop),NULL);
}

double GStopWatch::getElapsedTime() {  
  timeval res;
  timersub(&(timer.stop),&(timer.start),&res);
  return res.tv_sec + res.tv_usec/1000000.0; // 10^6 uSec per second
}

#endif