-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.h
More file actions
31 lines (25 loc) · 701 Bytes
/
timer.h
File metadata and controls
31 lines (25 loc) · 701 Bytes
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
#ifndef TIMER_H
#define TIMER_H
#include <chrono>
#include <ctime>
#include <iomanip>
#include <string>
#include <sstream>
typedef std::chrono::high_resolution_clock Clock;
typedef std::chrono::duration<int> Duration;
typedef std::chrono::seconds Seconds;
typedef std::chrono::time_point<Clock> Timepoint;
template <typename T>
int convertToInt(const T& time)
{
return std::chrono::duration_cast<Seconds>(time).count();
}
template <typename T>
std::string timeToString(T&& time)
{
auto a_time_t = Clock::to_time_t(time);
std::stringstream ss;
ss << std::put_time(std::localtime(&a_time_t), "%Y-%m-%d %H:%M:%S");
return ss.str();
}
#endif // TIMER_H