Created
April 5, 2013 12:19
-
-
Save wilburding/5318870 to your computer and use it in GitHub Desktop.
time any callable
This file contains hidden or 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
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