Skip to content

Instantly share code, notes, and snippets.

@wilburding
Created April 5, 2013 12:19
Show Gist options
  • Save wilburding/5318870 to your computer and use it in GitHub Desktop.
Save wilburding/5318870 to your computer and use it in GitHub Desktop.
time any callable
template<class F, class ...Args>
void timeit(uint32_t repeat, F&& f, Args&&... args)
{
auto begin_time = chrono::high_resolution_clock::now();
for(uint32_t i = 0; i < repeat; ++i)
f(forward<Args>(args)...);
auto end_time = chrono::high_resolution_clock::now();
printf("total time: %lldus\n", chrono::duration_cast<chrono::microseconds>(end_time - begin_time).count());
printf("average time: %lldns\n", chrono::duration_cast<chrono::nanoseconds>(end_time - begin_time).count() / repeat);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment