-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.h
More file actions
36 lines (28 loc) · 680 Bytes
/
timer.h
File metadata and controls
36 lines (28 loc) · 680 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
#ifndef ALGORITHMS_TIMER_H_
#define ALGORITHMS_TIMER_H_
#include <chrono>
#include <iostream>
#include <string>
class Timer
{
public:
void start();
void stop(const std::string &text);
private:
std::chrono::time_point<std::chrono::steady_clock> stamp;
};
void Timer::start()
{
stamp = std::chrono::steady_clock::now();
}
void Timer::stop(const std::string &text)
{
auto end = std::chrono::steady_clock::now();
auto diff = end - stamp;
std::chrono::duration<int, std::milli> diff_sec = std::chrono::duration_cast<std::chrono::milliseconds>(diff);
if (!text.empty())
{
std::cout << text << diff_sec.count() << " ms" << std::endl;
}
}
#endif ALGORITHMS_TIMER_H_