-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelapsed.hpp
45 lines (38 loc) · 915 Bytes
/
elapsed.hpp
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
#ifndef ELAPSED_HPP
#define ELAPSED_HPP
#include <thread>
#include <chrono>
#include <iostream>
#include <string>
class Elapsed
{
private:
std::chrono::high_resolution_clock::time_point start;
public:
inline void Start();
double End(std::string name);
double End();
};
// START
inline void Elapsed::Start()
{
this->start = std::chrono::high_resolution_clock::now();
};
// END
// returns time in millisonds and prints a string with
// a name parameter
inline double Elapsed::End(std::string name)
{
double e = this->End();
std::cout << name << " (" << e << "ms)" << std::endl;
return e;
};
// END
// returns elapsed time in milliseconds
inline double Elapsed::End()
{
std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now();
std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - this->start);
return ms.count();
};
#endif