-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimer.hpp
115 lines (92 loc) · 2.58 KB
/
Timer.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef TIMER_HPP
#define TIMER_HPP
#include <chrono>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include "utils/StatisticalSummary.hpp"
namespace TimerRegister {
using namespace std;
using namespace chrono;
using clock = high_resolution_clock;
using nanoseconds = duration<double, nano>;
struct Timing {
Timing();
Timing(nanoseconds time);
explicit operator nanoseconds() const;
explicit operator string() const;
Timing& operator=(const double &time);
static vector<string>
align_timings(const vector<pair<string,Timing>> &data);
hours::rep hrs;
minutes::rep mins;
seconds::rep secs;
milliseconds::rep msecs;
microseconds::rep usecs;
nanoseconds::rep nsecs;
nanoseconds::rep total_time;
};
struct Epoch {
struct TimerData {
TimerData(const string& name, const StatisticalSummary<Timing>&);
string name;
StatisticalSummary<Timing> results;
};
Epoch(const string& name, vector<TimerData>&&);
string name;
vector<TimerData> data;
};
vector<Epoch> get_epochs();
};
class Epoch
{
public:
Epoch() = delete;
Epoch(const Epoch&) = delete;
Epoch(Epoch&&) = delete;
Epoch(bool humanReadable = false, const std::string& = std::string());
Epoch
( std::ofstream&&
, const std::string& = std::string()
, bool humanReadable = false
);
Epoch
( std::ofstream&&
, bool humanReadable = false
, const std::string& = std::string()
);
Epoch
( const std::string&
, bool humanReadable = false
, const std::string& = std::string()
);
Epoch
( const std::string&
, const std::string& = std::string()
, bool humanReadable = false
);
~Epoch();
void set_output(const std::string&);
void set_output(std::ofstream&&);
void print_results(std::ostream&, bool humanReadable = false);
private:
bool direct_printed;
bool human_readable;
std::ofstream output;
size_t index;
};
class Timer
{
public:
Timer(const std::string&, size_t = 10);
Timer(const Timer&) = delete;
Timer(Timer&&) = default;
void start();
void stop();
void reserve(size_t);
private:
TimerRegister::clock::time_point begin;
std::shared_ptr<std::vector<TimerRegister::nanoseconds>> timings;
};
#endif