Created
July 12, 2018 13:36
-
-
Save sjgriffiths/c034f21ca9a6eea5428cbe3298398128 to your computer and use it in GitHub Desktop.
Simple function timer (C++)
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
//Times a given function call, plus arguments, in seconds | |
//Change to Args& if reference passing is required | |
template <typename F, typename... Args> | |
double timeFunc(F func, Args... args) | |
{ | |
using clock = std::chrono::high_resolution_clock; | |
auto t0 = clock::now(); | |
func(args...); | |
auto t1 = clock::now(); | |
return std::chrono::duration<double>(t1 - t0).count(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment