-
Notifications
You must be signed in to change notification settings - Fork 0
/
utimer.cpp
42 lines (32 loc) · 1.13 KB
/
utimer.cpp
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
42
#include <iostream>
#include <chrono>
#define START(timename) auto timename = std::chrono::system_clock::now();
#define STOP(timename,elapsed) auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - timename).count();
class utimer {
std::chrono::system_clock::time_point start;
std::chrono::system_clock::time_point stop;
std::string message;
using usecs = std::chrono::microseconds;
using msecs = std::chrono::milliseconds;
private:
long * us_elapsed;
public:
utimer(const std::string m) : message(m),us_elapsed((long *)NULL) {
start = std::chrono::system_clock::now();
}
utimer(const std::string m, long * us) : message(m),us_elapsed(us) {
start = std::chrono::system_clock::now();
}
~utimer() {
stop =
std::chrono::system_clock::now();
std::chrono::duration<double> elapsed =
stop - start;
auto musec =
std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count();
std::cout << message << " computed in " << musec << " usec "
<< std::endl;
if(us_elapsed != NULL)
(*us_elapsed) = musec;
}
};