-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClock.h
More file actions
42 lines (35 loc) · 954 Bytes
/
Clock.h
File metadata and controls
42 lines (35 loc) · 954 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
31
32
33
34
35
36
37
38
39
40
41
42
/*
I really should have named this Timer, shouldn't I have?
When you create a timer object, it keeps track of a description,
some string of your choosing, and the start time, which is handled in
the constructor. Stopping the clock outputs the total time that the
Clock was running.
ChRiStIaN fUsCo \o/\o/\o/
*/
#ifndef CLOCK_H
#define CLOCK_H
#include <iostream>
#include <cstdio>
#include <ctime>
#include <string>
class Clock {
private:
std::clock_t start;
std::string des;
public:
Clock(std::string descriptor);
double stopClock();
};
Clock::Clock(std::string descriptor)
{
std::cout << "Clock started with descriptor: " << descriptor << "\n";
des = descriptor;
start = std::clock();
}
double Clock::stopClock()
{
double dur = (std::clock() - start) / (double)CLOCKS_PER_SEC;
std::cout << "Clock with descriptor: " << des << " took " << dur << " seconds.\n";
return dur;
}
#endif // !CLOCK_H