Skip to content

Instantly share code, notes, and snippets.

@Kaminate
Created August 6, 2013 05:59
Show Gist options
  • Save Kaminate/6162377 to your computer and use it in GitHub Desktop.
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.
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