-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathStopWatch.cpp
More file actions
62 lines (52 loc) · 1.15 KB
/
Copy pathStopWatch.cpp
File metadata and controls
62 lines (52 loc) · 1.15 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "StopWatch.h"
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(WIN32)
StopWatch::StopWatch():elapsed_(0)
{
elapsed_ = 0;
start_.QuadPart = 0;
stop_.QuadPart = 0;
QueryPerformanceFrequency(&frequency_);
}
#else
StopWatch::StopWatch():elapsed_(0),start_(MicroSeconds::zero()),stop_(MicroSeconds::zero())
{
}
#endif
StopWatch::~StopWatch()
{
}
void StopWatch::Start()
{
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(WIN32)
QueryPerformanceCounter(&start_);
#else
start_ = Clock::now();
#endif
}
void StopWatch::Stop()
{
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(WIN32)
QueryPerformanceCounter(&stop_);
elapsed_ += (stop_.QuadPart - start_.QuadPart) * 1000000 / frequency_.QuadPart;
#else
stop_ = Clock::now();
elapsed_ = std::chrono::duration_cast<MicroSeconds>(stop_ - start_).count();
#endif
}
void StopWatch::ReStart()
{
elapsed_ = 0;
Start();
}
double StopWatch::Elapsed()
{
return static_cast<double>(elapsed_);
}
double StopWatch::ElapsedMS()
{
return elapsed_ / 1000.0;
}
double StopWatch::ElapsedSecond()
{
return elapsed_ / 1000000.0;
}