-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.h
More file actions
34 lines (28 loc) · 736 Bytes
/
profile.h
File metadata and controls
34 lines (28 loc) · 736 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
#pragma once
#include <chrono>
#include <iostream>
#include <string>
using namespace std;
using namespace std::chrono;
class LogDuration {
public:
explicit LogDuration(const string& msg = "")
: message(msg + ": ")
, start(steady_clock::now())
{
}
~LogDuration() {
auto finish = steady_clock::now();
auto dur = finish - start;
cerr << message
<< duration_cast<milliseconds>(dur).count()
<< " ms" << endl;
}
private:
string message;
steady_clock::time_point start;
};
#define UNIQ_ID_IMPL(lineno) _a_local_var_##lineno
#define UNIQ_ID(lineno) UNIQ_ID_IMPL(lineno)
#define LOG_DURATION(message) \
LogDuration UNIQ_ID(__LINE__){message};