-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.h
More file actions
30 lines (27 loc) · 997 Bytes
/
Copy pathTimer.h
File metadata and controls
30 lines (27 loc) · 997 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
#include <chrono>
#include <string>
#include <iostream>
#include <fstream>
class Timer {
public:
Timer(const std::string &name) : _name(name) {};
void start() {
_begin = std::chrono::high_resolution_clock::now();
}
void stop(const std::string &arr_name) {
_end = std::chrono::high_resolution_clock::now();
_duration_time = _end - _begin;
std::cout << arr_name << " : " << _duration_time.count() << " ms." << std::endl;
std::string filename = _name + ".txt";
std::ofstream record;
record.open(filename, std::ios_base::app);
record << arr_name << " : " << _duration_time.count() << " ms" << std::endl;
record.close();
}
~Timer() {};
private:
std::string _name;
std::chrono::time_point<std::chrono::high_resolution_clock> _begin;
std::chrono::time_point<std::chrono::high_resolution_clock> _end;
std::chrono::duration<double, std::milli> _duration_time;
};