sospin is hosted by Hepforge, IPPP Durham
SOSpin  1.0.0
timer.h
Go to the documentation of this file.
1 // Timer.h
3 // =======
4 // High Resolution Timer.
5 // This timer is able to measure the elapsed time with 1 micro-second accuracy
6 // in both Windows, Linux and Unix system
7 //
8 // AUTHOR: Song Ho Ahn (song.ahn@gmail.com)
9 // CREATED: 2003-01-13
10 // UPDATED: 2006-01-13
11 //
12 // Copyright (c) 2003 Song Ho Ahn
14 
15 
16 
17 
23 #ifndef TIMER_H_DEF
24 #define TIMER_H_DEF
25 
26 
27 #include <iostream>
28 #include <cstring>
29 #include <sstream>
30 #include <cstdlib>
31 #include <string>
32 
33 #ifdef WIN32 // Windows system specific
34 #include <windows.h>
35 #else // Unix based system specific
36 #include <sys/time.h>
37 #endif
38 
39 
40 
41 const std::string currentDateTime();
42 
43 
48 class Timer{
49 public:
51  Timer();
53  ~Timer();
54 
56  void start();
58  void stop();
60  double getElapsedTime();
62  double getElapsedTimeInSec();
64  double getElapsedTimeInMilliSec();
66  double getElapsedTimeInMicroSec();
67 
68 
69 protected:
70 
71 
72 private:
78  int stopped;
79 #ifdef WIN32
80  LARGE_INTEGER frequency; // ticks per second
81  LARGE_INTEGER startCount; //
82  LARGE_INTEGER endCount; //
83 #else
84  timeval startCount; //
85  timeval endCount; //
86 #endif
87 };
88 
89 #endif // TIMER_H_DEF
double getElapsedTimeInSec()
Get elapsed time in second (same as getElapsedTime)
Definition: timer.cpp:116
timeval endCount
Definition: timer.h:85
~Timer()
Destructor.
Definition: timer.cpp:56
double endTimeInMicroSec
Store ending time in micro-second.
Definition: timer.h:76
int stopped
Stop flag.
Definition: timer.h:78
const std::string currentDateTime()
Get current date/time, format is YYYY-MM-DD.HH:mm:ss.
Definition: timer.cpp:27
Timer()
Constructor.
Definition: timer.cpp:40
void start()
Start timer.
Definition: timer.cpp:62
timeval startCount
Definition: timer.h:84
double getElapsedTimeInMilliSec()
Get elapsed time in milli-second.
Definition: timer.cpp:109
double getElapsedTimeInMicroSec()
Get elapsed time in micro-second.
Definition: timer.cpp:88
double getElapsedTime()
Get elapsed time in second.
Definition: timer.cpp:123
double startTimeInMicroSec
Store starting time in micro-second.
Definition: timer.h:74
Measure elapsed time.
Definition: timer.h:48
void stop()
Stop the timer.
Definition: timer.cpp:74