-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChronoCHARLOT.cpp
60 lines (52 loc) · 1.38 KB
/
ChronoCHARLOT.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
52
53
54
55
56
57
58
59
60
#include "ChronoCHARLOT.hpp"
#include <iostream>
#include <chrono>
#include <random>
#include <ctime>
#include <vector>
using namespace std;
Chrono::Chrono(float elapsed_time,string newPrecision):_elapsed_time(elapsed_time),_precision(newPrecision),_isCalculing(false)
{}
void
Chrono::start()
{
_isCalculing=true;
_start = chrono::system_clock::now();
}
void
Chrono::stop()
{
if(_isCalculing==true)
{
chrono::time_point<chrono::system_clock> end=chrono::system_clock::now();
_isCalculing=false;
if(_precision=="nanoseconds")
{
_elapsed_time+=chrono::duration_cast<chrono::nanoseconds>(end-_start).count();
}
else if(_precision=="microseconds")
{
_elapsed_time+=chrono::duration_cast<chrono::microseconds>(end-_start).count();
}
else if(_precision=="seconds")
{
_elapsed_time+=chrono::duration_cast<chrono::seconds>(end-_start).count();
}
else
{
_elapsed_time+=chrono::duration_cast<chrono::milliseconds>(end-_start).count();
}
}
else
cerr << "Le chrono n'a pas démarré, vous ne pouvez pas le stopper" << endl;
}
void
Chrono::reset()
{
_elapsed_time=0;
}
float
Chrono::getDuration()
{
return _elapsed_time;
}