-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgress.cpp
More file actions
46 lines (39 loc) · 1.39 KB
/
Progress.cpp
File metadata and controls
46 lines (39 loc) · 1.39 KB
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
/******************************************************************************
* @file Progress.cpp
* @author Andrés Gavín Murillo, 716358
* @author Abel Naya Forcano, 544125
* @date Enero 2020
* @coms Informática Gráfica - Trabajo 4: Path tracer
******************************************************************************/
#include "Progress.hpp"
#include <iostream>
#include <iomanip>
void Progress::start(const std::string &prefix) {
using namespace std::chrono;
this->startTime = high_resolution_clock::now();
this->prefix = prefix;
this->step(0);
}
void Progress::step(float currentStep) {
using namespace std;
cout << "\r" << this->prefix << " progress : " << fixed << setprecision(3) << currentStep << "%" << flush;
}
void Progress::end() {
using namespace std::chrono;
auto stop = high_resolution_clock::now();
auto dur = stop - this->startTime;
auto h = duration_cast<hours>(dur);
auto m = duration_cast<minutes>(dur -= h);
auto s = duration_cast<seconds>(dur -= m);
auto ms = duration_cast<milliseconds>(dur -= s);
using namespace std;
cout << "\r" << this->prefix << " finished in ";
if (h.count() != 0) {
cout << h.count() << "d ";
}
if (m.count() != 0) {
cout << m.count() << "m ";
}
cout << s.count() << "," << setfill('0') << setw(3) << ms.count() << "s";
cout << endl;
}