Created
July 31, 2015 20:34
-
-
Save bbkane/3f503791d864883b1121 to your computer and use it in GitHub Desktop.
Simple function to time different versions of a class
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
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