Skip to content

Instantly share code, notes, and snippets.

@rti
Created January 13, 2012 10:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rti/1605397 to your computer and use it in GitHub Desktop.
Save rti/1605397 to your computer and use it in GitHub Desktop.
KISS cpp profiling - easy to use cpu time measurement helper
/*
* 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