-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathStopWatch.cc
78 lines (61 loc) · 1.9 KB
/
StopWatch.cc
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/** Copyright 2025 RWTH Aachen University. All rights reserved.
*
* Licensed under the RWTH ASR License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.hltpr.rwth-aachen.de/rwth-asr/rwth-asr-license.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "StopWatch.hh"
#include "Utility.hh"
namespace Core {
StopWatch::StopWatch()
: running_(false), startTime_(), elapsedSeconds_(0.0) {}
void StopWatch::start() {
if (running_) {
return;
}
TIMER_START(startTime_);
running_ = true;
}
void StopWatch::stop() {
if (not running_) {
return;
}
timeval endTime;
TIMER_STOP(startTime_, endTime, elapsedSeconds_);
running_ = false;
}
void StopWatch::reset() {
elapsedSeconds_ = 0;
running_ = false;
}
double StopWatch::elapsedSeconds() const {
if (running_) {
timeval endTime;
double currentTime = 0; // in seconds
// Note: This macro doesn't actually "stop" anything, it just writes into `endTime` and `currentTime`
TIMER_STOP(const_cast<timeval&>(startTime_), endTime, currentTime);
return elapsedSeconds_ + currentTime;
}
return elapsedSeconds_;
}
double StopWatch::elapsedCentiseconds() const {
return elapsedSeconds() * 1e2;
}
double StopWatch::elapsedMilliseconds() const {
return elapsedSeconds() * 1e3;
}
double StopWatch::elapsedMicroseconds() const {
return elapsedSeconds() * 1e6;
}
double StopWatch::elapsedNanoseconds() const {
return elapsedSeconds() * 1e9;
}
} // namespace Core