-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.cpp
More file actions
38 lines (36 loc) · 928 Bytes
/
timer.cpp
File metadata and controls
38 lines (36 loc) · 928 Bytes
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
#include "include\includes.h"
#include "include\timer.h"
double total_time = 0;
Timer::Timer() : is_running(false)
{
}
void Timer::start() //Ôóíêöèÿ íà÷àëà òàéìåðà
{
if (!is_running)
{
start_time = high_resolution_clock::now();
is_running = true;
}
}
void Timer::stop() //Ôóíêöèÿ êîíöà òàéìåðà
{
if (is_running)
{
stop_time = high_resolution_clock::now();
is_running = false;
}
}
double Timer::get_elapsed_time() const //Ôóíêöèÿ äëÿ ïîëó÷åíèÿ ïðîøåäøåíð âðåìåíè
{
if (is_running)
{
auto now = high_resolution_clock::now();
total_time = duration<double>(now - start_time).count();
return duration<double>(now - start_time).count();
}
else
{
total_time = duration<double>(stop_time - start_time).count();
return duration<double>(stop_time - start_time).count();
}
}