Skip to content

Instantly share code, notes, and snippets.

@bbkane
Created July 31, 2015 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbkane/3f503791d864883b1121 to your computer and use it in GitHub Desktop.
Save bbkane/3f503791d864883b1121 to your computer and use it in GitHub Desktop.
Simple function to time different versions of a class
template<typename T>
int time_it()
{
using milliseconds_t = std::chrono::duration < int, std::milli >;
//start time
auto start = std::chrono::steady_clock::now();
//instantiate class
T class_to_time;
//do stuff to time it
class_to_time.do_something();
class_to_time.do_something_else();
//get time and return
auto end = std::chrono::steady_clock::now();
auto duration = std::chrono::duration_cast<milliseconds_t>(end - start);
return duration.count();
}
// usage:
// std::cout << "-- Time: " << time_it<ClassVersion1>();
// std::cout << "-- Time: " << time_it<ClassVersion2>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment