forked from swayfreeda/ImageBasedModellingEduV1.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.cpp
executable file
·60 lines (51 loc) · 1.86 KB
/
timer.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
/*
* Copyright (C) 2015, Nils Moehrle
* TU Darmstadt - Graphics, Capture and Massively Parallel Computing
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the BSD 3-Clause license. See the LICENSE.txt file for details.
*/
#include "timer.h"
Timer::Timer(void) {
header = "";
ctimer = util::ClockTimer();
wtimer = util::WallTimer();
}
Timer::Timer(std::string const & _header) {
header = _header;
ctimer = util::ClockTimer();
wtimer = util::WallTimer();
}
void Timer::measure(std::string const & eventname) {
std::size_t abs_clocks = ctimer.get_elapsed();
std::size_t abs_milliseconds = wtimer.get_elapsed();
if(events.empty()) {
Event event = {eventname, abs_clocks, abs_milliseconds, abs_clocks, abs_milliseconds};
events.push_back(event);
} else {
Event last_event = events.back();
std::size_t rel_clocks = abs_clocks - last_event.abs_clocks;
std::size_t rel_milliseconds = abs_milliseconds - last_event.abs_milliseconds;
Event event = {eventname, abs_clocks, abs_milliseconds, rel_clocks, rel_milliseconds};
events.push_back(event);
}
}
void Timer::write_to_file(std::string const & filename) const {
std::ofstream out(filename.c_str());
if (!out.good())
throw util::FileException(filename, std::strerror(errno));
if(!header.empty())
out << "#" << header << std::endl;
out << "Event, Absolute clocks, Absolute milliseconds, Relative clocks, Relative milliseconds"
<< std::endl;
for (std::size_t i = 0; i < events.size(); ++i) {
Event event = events[i];
out << event.name << ", "
<< event.abs_clocks << ", "
<< event.abs_milliseconds << ", "
<< event.rel_clocks << ", "
<< event.rel_milliseconds << std::endl;
}
out.close();
}