Created
August 6, 2013 05:59
-
-
Save Kaminate/6162377 to your computer and use it in GitHub Desktop.
Cute little profiler from ThatGameCompany.
Constructor starts ticking, Destructor prints the time taken.
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
class Profiler | |
{ | |
public: | |
Profiler(); | |
~Profiler(); // couts the amount of time the profiler was alive | |
private: | |
float GetTime(); | |
float startSeconds; | |
float endSeconds; | |
}; | |
#include <time.h> // clock | |
#include <iostream.h> // cout | |
float Profiler::GetTime() | |
{ | |
return clock() / (float) CLOCKS_PER_SEC; | |
} | |
Profiler::Profiler() | |
{ | |
startSeconds = GetTime(); | |
} | |
Profiler::~Profiler() | |
{ | |
endSeconds = GetTime(); | |
std::cout << "Time taken: " << endSeconds - startSeconds << "seconds." << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment