-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientTimer.cpp
52 lines (44 loc) · 1.11 KB
/
ClientTimer.cpp
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
#include <iomanip>
#include <iostream>
#include "ClientTimer.h"
ClientTimer::ClientTimer() {
sum = duration<double, std::micro>(0);
max = duration<double, std::micro>(0);
min = duration<double, std::micro>(9999999999.9f);
op_count = 0;
}
void ClientTimer::Start() {
start_time = high_resolution_clock::now();
}
void ClientTimer::End() {
auto end_time = high_resolution_clock::now();
elapsed_time = (end_time - start_time);
}
void ClientTimer::EndAndMerge() {
End();
op_count++;
sum += elapsed_time;
if (elapsed_time < min) {
min = elapsed_time;
}
if (elapsed_time > max) {
max = elapsed_time;
}
}
void ClientTimer::Merge(ClientTimer timer) {
sum += timer.sum;
op_count += timer.op_count;
if (timer.min < min) {
min = timer.min;
}
if (timer.max > max) {
max = timer.max;
}
}
void ClientTimer::PrintStats() {
std::cout << std::fixed << std::setprecision(3);
std::cout << "avg: " << sum.count() / op_count << "\t";
std::cout << "min: "<<min.count() << "\t";
std::cout << "max: "<<max.count() << "\t";
std::cout << "throughput: "<< op_count / elapsed_time.count() * 1000000.0f << std::endl;
}