Last active
September 26, 2020 02:50
-
-
Save amigo421/2a5c7527bbc65285ea6c82ae0417ad89 to your computer and use it in GitHub Desktop.
wrapper to measure of time execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
usage: std::cout << measure<>::execution(functor(dummy)) << std::endl | |
*/ | |
template <typename TimeT = std::chrono::nanoseconds> struct measure { | |
template <typename F, typename... Args> | |
static typename TimeT::rep execution(F func, Args &&... args) { | |
auto start = std::chrono::steady_clock::now(); | |
func(std::forward<Args>(args)...); | |
auto duration = std::chrono::duration_cast<TimeT>( | |
std::chrono::steady_clock::now() - start); | |
return duration.count(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment