1
- //
2
- // Created by Ivan Shynkarenka on 03.07.2015.
3
- //
1
+ /* !
2
+ \file phase_metrics.h
3
+ \brief Benchmark phase metrics definition
4
+ \author Ivan Shynkarenka
5
+ \date 03.07.2015
6
+ \copyright MIT License
7
+ */
4
8
5
9
#ifndef CPPBENCHMARK_PHASE_METRICS_H
6
10
#define CPPBENCHMARK_PHASE_METRICS_H
7
11
8
12
#include < chrono>
9
13
#include < cstdint>
10
14
#include < limits>
15
+ #include < unordered_map>
11
16
12
17
namespace CppBenchmark {
13
18
19
+ // ! Benchmark phase metrics
20
+ /* !
21
+ Provides interface of the phase metrics to collect benchmark running statistics:
22
+ - Average time of the phase execution
23
+ - Minimal time of the phase execution
24
+ - Maximal time of the phase execution
25
+ - Total time of the phase execution
26
+ - Total iterations made in the phase
27
+ - Total items processed in the phase
28
+ - Total bytes processed in the phase
29
+
30
+ If the phase metrics is accessed from benchmark running Context you can update some metrics values:
31
+ - increase iterations count with AddIterations() method
32
+ - register processed items with AddItems() method
33
+ - register processed bytes with AddBytes() method
34
+ - set custom integer/string values by name
35
+ */
14
36
class PhaseMetrics
15
37
{
16
38
friend class PhaseCore ;
17
39
18
40
public:
41
+ // ! Default constructor
19
42
PhaseMetrics () noexcept
20
43
: _min_time(std::numeric_limits<int64_t >::max()),
21
44
_max_time (std::numeric_limits<int64_t >::min()),
@@ -31,33 +54,77 @@ class PhaseMetrics
31
54
PhaseMetrics& operator =(const PhaseMetrics&) noexcept = default ;
32
55
PhaseMetrics& operator =(PhaseMetrics&&) noexcept = default ;
33
56
57
+ // ! Get average time of the phase execution
34
58
int64_t avg_time () const noexcept ;
59
+ // ! Get minimal time of the phase execution
35
60
int64_t min_time () const noexcept ;
61
+ // ! Get maximal time of the phase execution
36
62
int64_t max_time () const noexcept ;
37
63
64
+ // ! Get total time of the phase execution
38
65
int64_t total_time () const noexcept { return _total_time; }
66
+ // ! Get total iterations made in the phase
39
67
int64_t total_iterations () const noexcept { return _total_iterations; }
68
+ // ! Get total items processed in the phase
40
69
int64_t total_items () const noexcept { return _total_items; }
70
+ // ! Get total bytes processed in the phase
41
71
int64_t total_bytes () const noexcept { return _total_bytes; }
42
72
73
+ // ! Get iterations throughput (iterations / second)
43
74
int64_t iterations_per_second () const noexcept ;
75
+ // ! Get items throughput (items / second)
44
76
int64_t items_per_second () const noexcept ;
77
+ // ! Get data throughput (bytes / second)
45
78
int64_t bytes_per_second () const noexcept ;
46
79
80
+ // ! Get custom integers hash table
81
+ const std::unordered_map<std::string, int >& custom_int () const noexcept { return _custom_int; }
82
+ // ! Get custom strings hash table
83
+ const std::unordered_map<std::string, std::string>& custom_str () const noexcept { return _custom_str; }
84
+
85
+ // ! Increase iterations count of the current phase
86
+ /* !
87
+ \param iterations - Iterations count
88
+ */
47
89
void AddIterations (int64_t iterations) noexcept
48
90
{ _total_iterations += iterations; }
91
+ // ! Register processed items in the current phase
92
+ /* !
93
+ \param items - Items count
94
+ */
49
95
void AddItems (int64_t items) noexcept
50
96
{ _total_items += items; }
97
+ // ! Register processed bytes in the current phase
98
+ /* !
99
+ \param bytes - Bytes count
100
+ */
51
101
void AddBytes (int64_t bytes) noexcept
52
102
{ _total_bytes += bytes; }
53
103
104
+ // ! Set custom integer value
105
+ /* !
106
+ \param name - Name
107
+ \param value - Value
108
+ */
109
+ void SetCustom (const std::string& name, int value) noexcept
110
+ { _custom_int[name] = value; }
111
+ // ! Set custom string value
112
+ /* !
113
+ \param name - Name
114
+ \param value - Value
115
+ */
116
+ void SetCustom (const std::string& name, const std::string& value) noexcept
117
+ { _custom_str[name] = value; }
118
+
54
119
private:
55
120
int64_t _min_time;
56
121
int64_t _max_time;
57
122
int64_t _total_time;
58
123
int64_t _total_iterations;
59
124
int64_t _total_items;
60
125
int64_t _total_bytes;
126
+ std::unordered_map<std::string, int > _custom_int;
127
+ std::unordered_map<std::string, std::string> _custom_str;
61
128
62
129
std::chrono::high_resolution_clock::time_point _timestamp;
63
130
0 commit comments