-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtiming.cpp
49 lines (41 loc) · 1.82 KB
/
timing.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
//
// Created by nick434434 on 23/10/2019.
//
#include "timing.h"
#include <iostream>
#include <iomanip>
void timing::start_clock() {
t0 = std::chrono::high_resolution_clock::now();
}
timing::Time timing::reset_clock(std::string& message, std::ostream& out) {
if (message.length() > 40)
message.resize(40);
auto diff = std::chrono::high_resolution_clock::now() - t0;
t0 = std::chrono::high_resolution_clock::now();
Time tt = Time(std::chrono::duration_cast<std::chrono::microseconds>(diff).count());
out << "Global clock reset due to \"" << std::setw(40) << std::left << message << "\" on " <<
std::setw(10) << std::setprecision(2) << std::left << std::fixed << tt << " seconds" << std::endl;
return tt;
}
timing::Time timing::check_clock() {
return Time(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - t0).count());
}
void timing::start_local_clock() {
t1 = std::chrono::high_resolution_clock::now();
}
timing::Time timing::reset_local_clock(std::string& message, std::ostream& out) {
if (message.length() > 40)
message.resize(40);
auto diff = std::chrono::high_resolution_clock::now() - t1;
t1 = std::chrono::high_resolution_clock::now();
Time tt = Time(std::chrono::duration_cast<std::chrono::microseconds>(diff).count());
out << "Local clock reset due to \"" << std::setw(40) << std::left << message << "\" on " <<
std::setw(10) << std::setprecision(2) << std::left << std::fixed << tt << " seconds" << std::endl;
return tt;
}
timing::Time timing::check_local_clock() {
return Time(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - t1).count());
}
std::ostream& operator<<(std::ostream& op_out, timing::Time t) {
op_out << t.as_seconds(); return op_out;
}