-
Notifications
You must be signed in to change notification settings - Fork 3
/
ExecutionTimer.h
53 lines (42 loc) · 1.41 KB
/
ExecutionTimer.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: ExecutionTimer.h
* Author: Truong
*
* Created on July 8, 2021, 10:40 PM
*/
#ifndef EXECUTION_TIMER_H
#define EXECUTION_TIMER_H
#include <chrono>
#include <sstream>
using namespace std;
template<class Resolution = std::chrono::milliseconds>
class ExecutionTimer {
private:
const std::chrono::high_resolution_clock::time_point mStart = std::chrono::high_resolution_clock::now();
public:
ExecutionTimer() = default;
~ExecutionTimer() {
const auto end = std::chrono::high_resolution_clock::now();
std::ostringstream strStream;
strStream << "Destructor Elapsed: "
<< std::chrono::duration_cast<Resolution>( end - mStart ).count()
<< " miliSeconds."
<< std::endl;
std::cout << strStream.str() << std::endl;
}
inline void stop() {
const auto end = std::chrono::high_resolution_clock::now();
std::ostringstream strStream;
strStream << "Stop Elapsed: "
<< std::chrono::duration_cast<Resolution>(end - mStart).count()
<< " miliSeconds."
<< std::endl;
std::cout << strStream.str() << std::endl;
}
}; // ExecutionTimer
#endif // EXECUTION_TIMER_H