forked from SurfaceMan/surface_match
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.h
34 lines (28 loc) · 831 Bytes
/
helper.h
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
#pragma once
#include <chrono>
#include <iostream>
#include <string>
namespace ppf {
class Timer {
public:
Timer(std::string content)
: content_(std::move(content))
, start_(std::chrono::steady_clock::now())
, released(false) {
}
~Timer() {
if (!released)
release();
}
void release() {
released = true;
auto end = std::chrono::steady_clock::now();
auto cost = std::chrono::duration_cast<std::chrono::milliseconds>(end - start_);
std::cout << content_ << " cost(ms): " << cost.count() << std::endl;
}
private:
std::string content_;
std::chrono::time_point<std::chrono::steady_clock> start_;
bool released;
};
} // namespace ppf