Created
January 13, 2012 10:09
-
-
Save rti/1605397 to your computer and use it in GitHub Desktop.
KISS cpp profiling - easy to use cpu time measurement helper
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
/* | |
* USAGE: | |
* #include <ctime> | |
* ... | |
* void your_func() { | |
* measure_time t(__func__); | |
* // your code... | |
* } | |
*/ | |
struct measure_time { | |
clock_t start, end; | |
const char* name; | |
measure_time(const char* p_name) : name(p_name) { | |
start = clock(); | |
} | |
~measure_time() { | |
end = clock(); | |
printf(">> %s took %0.3fs\n", | |
name, static_cast<double>(end - start) / CLOCKS_PER_SEC); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment