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