add instrumentation for runtime measurement
This commit is contained in:
parent
0751b7734c
commit
2097c0fe36
22
timer.hpp
Normal file
22
timer.hpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef TIMER_H_
|
||||||
|
#define TIMER_H_
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <functional>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
template <class TimeUnit = std::chrono::microseconds,
|
||||||
|
class ClockType = std::chrono::steady_clock>
|
||||||
|
struct measure {
|
||||||
|
template <class F, class... Args>
|
||||||
|
static auto duration(F &&func, Args &&...args) {
|
||||||
|
auto start = ClockType::now();
|
||||||
|
auto retVal =
|
||||||
|
std::invoke(std::forward<F>(func), std::forward<Args>(args)...);
|
||||||
|
auto end = ClockType::now();
|
||||||
|
return std::make_pair(retVal,
|
||||||
|
std::chrono::duration_cast<TimeUnit>(end - start));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TIMER_H_
|
||||||
Loading…
x
Reference in New Issue
Block a user