-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.hpp
54 lines (42 loc) · 1.09 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
#ifndef TIMER_H
#define TIMER_H
#include <time.h>
#include <iostream>
#include <vector>
using namespace std;
class Timer{
private:
clock_t t;
float diff;
clock_t zero;
public:
float mseconds;
string name;
Timer(string name, clock_t t, clock_t prevTime){
this->t = t;
this->diff = (float)t - (float) prevTime;
this->name = name;
this->mseconds = (diff/CLOCKS_PER_SEC)*1000;
}
Timer(string name, float mseconds){
this->name = name;
this->mseconds = mseconds;
}
Timer& operator=(const Timer &other){
this->t = other.t;
this->diff = other.diff;
this->name = other.name;
this->mseconds = other.mseconds;
}
clock_t retTime(){
return t;
}
void print(){
cout << name << ": " << mseconds << "ms" << endl;
}
};
void addTime(string name, clock_t t, vector<Timer> ×);
void printTimes(vector<Timer> ×, int start, int end);
void totalTime(vector<Timer> ×, bool includeInit = true);
vector<Timer> averageArray(vector<vector<Timer>> &tests);
#endif