Skip to content

Instantly share code, notes, and snippets.

@amigo421
Last active September 26, 2020 02:50
Show Gist options
  • Save amigo421/2a5c7527bbc65285ea6c82ae0417ad89 to your computer and use it in GitHub Desktop.
Save amigo421/2a5c7527bbc65285ea6c82ae0417ad89 to your computer and use it in GitHub Desktop.
wrapper to measure of time execution
/**
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