forked from tapetums/include
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StopWatch.hpp
80 lines (62 loc) · 1.77 KB
/
StopWatch.hpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once
//---------------------------------------------------------------------------//
//
// StopWatch.hpp
// 経過時間の計測
// Copyright (C) 2011-2016 tapetums
//
//---------------------------------------------------------------------------//
#include <windows.h>
//---------------------------------------------------------------------------//
namespace tapetums
{
class StopWatch;
}
//---------------------------------------------------------------------------//
class tapetums::StopWatch
{
private:
INT64 frequency { 0 };
INT64 start_time { 0 };
INT64 stop_time { 0 };
public:
StopWatch() noexcept { reset(); }
~StopWatch() = default;
StopWatch(const StopWatch&) = delete;
StopWatch& operator =(const StopWatch&) = delete;
StopWatch(StopWatch&&) noexcept = delete;
StopWatch& operator =(StopWatch&&) noexcept = delete;
public:
void start() noexcept
{
::QueryPerformanceCounter((LARGE_INTEGER*)&start_time);
}
void stop() noexcept
{
::QueryPerformanceCounter((LARGE_INTEGER*)&stop_time);
}
void reset() noexcept
{
::QueryPerformanceFrequency((LARGE_INTEGER*)&frequency);
start_time = stop_time = 0;
}
public:
double sec() const noexcept
{
return 1.0 * (stop_time - start_time) / frequency;
}
double msec() const noexcept
{
return 1000.0 * (stop_time - start_time) / frequency;
}
double usec() const noexcept
{
return 1000.0 * 1000.0 * (stop_time - start_time) / frequency;
}
double nsec() const noexcept
{
return 1000.0 * 1000.0 * 1000.0 * (stop_time - start_time) / frequency;
}
};
//---------------------------------------------------------------------------//
// StopWatch.hpp