NIST Biometric Evaluation Framework
Software components for biometric technology evaluations
be_time_timer.h
Go to the documentation of this file.
1/*
2 * This software was developed at the National Institute of Standards and
3 * Technology (NIST) by employees of the Federal Government in the course
4 * of their official duties. Pursuant to title 17 Section 105 of the
5 * United States Code, this software is not subject to copyright protection
6 * and is in the public domain. NIST assumes no responsibility whatsoever for
7 * its use by other parties, and makes no guarantees, expressed or implied,
8 * about its quality, reliability, or any other characteristic.
9 */
10
11#ifndef __BE_TIME_TIMER_H__
12#define __BE_TIME_TIMER_H__
13
14#include <chrono>
15#include <cstdint>
16#include <functional>
17
18#include <be_time.h>
19
20namespace BiometricEvaluation
21{
22 namespace Time
23 {
38 class Timer
39 {
40 public:
43#ifdef __MIC__
44 std::chrono::monotonic_clock;
45#else
46 std::chrono::steady_clock;
47#endif
48
51
63 const std::function<void()> &func);
64
73 void
75
84 void
86
102 uint64_t
103 elapsed(bool nano = false)
104 const;
105
122 std::string
124 bool displayUnits = false,
125 bool nano = false)
126 const;
127
142 Timer&
144 const std::function<void()> &func);
145
146 private:
151 bool _inProgress;
152
154 BE_CLOCK_TYPE::time_point _start;
156 BE_CLOCK_TYPE::time_point _finish;
157 };
158
175 std::ostream&
177 std::ostream &s,
178 const Timer &timer);
179 }
180}
181
182#endif /* __BE_TIME_TIMER_H__ */
This class can be used by applications to report the amount of time a block of code takes to execute.
Definition: be_time_timer.h:39
Timer(const std::function< void()> &func)
Construct a timer and time a function immediately.
void stop()
Stop tracking time.
Timer()
Constructor for the Timer object.
std::string elapsedStr(bool displayUnits=false, bool nano=false) const
Convenience method for printing elapsed time as a string.
void start()
Start tracking time.
std::chrono::steady_clock BE_CLOCK_TYPE
Clock type to use, aliased for easy replacement.
Definition: be_time_timer.h:46
uint64_t elapsed(bool nano=false) const
Get the elapsed time in microseconds or nanoseconds between calls to this object's start() and stop()...
Timer & time(const std::function< void()> &func)
Record the runtime of a function.
std::ostream & operator<<(std::ostream &s, const Timer &timer)
Output stream operator overload for Timer.
This software was developed at the National Institute of Standards and Technology (NIST) by employees...