-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.h
44 lines (38 loc) · 1.31 KB
/
timer.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
/* Developed by Jimmy Hu */
#ifndef Timer_H
#define Timer_H
#include <chrono>
#include <iostream>
//#include <print>
namespace TinyDIP
{
class Timer
{
private:
std::chrono::system_clock::time_point start, end;
std::chrono::duration<double> elapsed_seconds;
std::time_t end_time;
public:
Timer()
{
start = std::chrono::system_clock::now();
}
~Timer()
{
end = std::chrono::system_clock::now();
elapsed_seconds = end - start;
end_time = std::chrono::system_clock::to_time_t(end);
if (elapsed_seconds.count() != 1)
{
//std::print(std::cout, "Computation finished at {} elapsed time: {} seconds.\n", std::ctime(&end_time), elapsed_seconds.count());
std::cout << "Computation finished at " << std::ctime(&end_time) << " elapsed time: " << elapsed_seconds.count() << "seconds.\n";
}
else
{
//std::print(std::cout, "Computation finished at {} elapsed time: {} second.\n", std::ctime(&end_time), elapsed_seconds.count());
std::cout << "Computation finished at " << std::ctime(&end_time) << " elapsed time: " << elapsed_seconds.count() << "second.\n";
}
}
};
}
#endif