code_profiler
include
profiling
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
#ifndef TIMER_H_DEF
16
#define TIMER_H_DEF
17
18
#ifdef WIN32 // Windows system specific
19
#include <windows.h>
20
#else // Unix based system specific
21
#include <sys/time.h>
22
#endif
23
24
#include <
iostream
>
25
#include <
string
>
26
27
28
class
Timer
29
{
30
public
:
31
Timer
();
// default constructor
32
~Timer
();
// default destructor
33
34
void
start
();
// start timer
35
void
stop
();
// stop the timer
36
double
getElapsedTime
()
const
;
// get elapsed time in second
37
double
getElapsedTimeInSec
()
const
;
// get elapsed time in second (same as getElapsedTime)
38
double
getElapsedTimeInMilliSec
()
const
;
// get elapsed time in milli-second
39
double
getElapsedTimeInMicroSec
()
const
;
// get elapsed time in micro-second
40
void
printLastElapsedTime
(
std::string
);
41
void
printLastElapsedTimeMSec
(
std::string
);
42
43
44
protected
:
45
46
47
private
:
48
// double startTimeInMicroSec; // starting time in micro-second
49
// double endTimeInMicroSec; // ending time in micro-second
50
int
stopped
;
// stop flag
51
#ifdef WIN32
52
LARGE_INTEGER frequency;
// ticks per second
53
LARGE_INTEGER startCount;
//
54
LARGE_INTEGER endCount;
//
55
#else
56
timeval
start_count_
;
//
57
timeval
end_count_
;
//
58
#endif
59
};
60
61
#define TIMER_START Timer t; t.start();
62
#define TIMER_STOP(x) (t. printLastElapsedTime(x))
63
#define TIMER_STOP_M(x) (t.printLastElapsedTimeMSec(x))
64
65
#endif // TIMER_H_DEF
Timer::start_count_
timeval start_count_
Definition:
Timer.h:56
std::string
Timer::~Timer
~Timer()
Definition:
Timer.cpp:40
Timer::getElapsedTimeInSec
double getElapsedTimeInSec() const
Definition:
Timer.cpp:121
iostream
Timer::getElapsedTime
double getElapsedTime() const
Definition:
Timer.cpp:131
Timer
Definition:
Timer.h:28
Timer::stopped
int stopped
Definition:
Timer.h:50
Timer::getElapsedTimeInMicroSec
double getElapsedTimeInMicroSec() const
Definition:
Timer.cpp:83
Timer::start
void start()
Definition:
Timer.cpp:50
Timer::end_count_
timeval end_count_
Definition:
Timer.h:57
Timer::getElapsedTimeInMilliSec
double getElapsedTimeInMilliSec() const
Definition:
Timer.cpp:111
Timer::Timer
Timer()
Definition:
Timer.cpp:21
Timer::printLastElapsedTime
void printLastElapsedTime(std::string)
Definition:
Timer.cpp:136
Timer::printLastElapsedTimeMSec
void printLastElapsedTimeMSec(std::string)
Definition:
Timer.cpp:142
Timer::stop
void stop()
Definition:
Timer.cpp:66
string
Generated on Sun Feb 23 2025 04:33:26 for code_profiler by
1.8.17