ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/gclib/gstopwatch.cpp
Revision: 18
Committed: Mon Jul 18 21:00:21 2011 UTC (8 years ago) by gpertea
File size: 934 byte(s)
Log Message:
added a few more source files, test code

Line User Rev File contents
1 gpertea 18 #include "gstopwatch.h"
2    
3     #ifdef __WIN32__
4     double GStopWatch::LIToSecs( LARGE_INTEGER & L) {
5     return ((double)L.QuadPart /(double)frequency.QuadPart);
6     }
7    
8     GStopWatch::GStopWatch(){
9     timer.start.QuadPart=0;
10     timer.stop.QuadPart=0;
11     QueryPerformanceFrequency( &frequency );
12     }
13    
14     void GStopWatch::startTimer( ) {
15     QueryPerformanceCounter(&timer.start);
16     }
17    
18     void GStopWatch::stopTimer( ) {
19     QueryPerformanceCounter(&timer.stop);
20     }
21    
22    
23     double GStopWatch::getElapsedTime() {
24     LARGE_INTEGER time;
25     time.QuadPart = timer.stop.QuadPart - timer.start.QuadPart;
26     return LIToSecs( time) ;
27     }
28     #else
29     //Linux code:
30     void GStopWatch::startTimer( ) {
31     gettimeofday(&(timer.start),NULL);
32     }
33    
34     void GStopWatch::stopTimer( ) {
35     gettimeofday(&(timer.stop),NULL);
36     }
37    
38     double GStopWatch::getElapsedTime() {
39     timeval res;
40     timersub(&(timer.stop),&(timer.start),&res);
41     return res.tv_sec + res.tv_usec/1000000.0; // 10^6 uSec per second
42     }
43    
44     #endif