Skip to content

Instantly share code, notes, and snippets.

@sjgriffiths
Created July 12, 2018 13:36
Show Gist options
  • Save sjgriffiths/c034f21ca9a6eea5428cbe3298398128 to your computer and use it in GitHub Desktop.
Save sjgriffiths/c034f21ca9a6eea5428cbe3298398128 to your computer and use it in GitHub Desktop.
Simple function timer (C++)
//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