#include "ProfileSample.h" #include "ProfilerLogHandler.h" // Profiler is only used in debug mode #define _DEBUG void SetUpGame() { PROFILE("Game Set-up"); //Make dummy use of processor: SDL_Delay(10); } void RenderTile() { //Make dummy use of processor: SDL_Delay(1); } void RenderUI() { PROFILE("UI Renderer"); //Make dummy use of processor: SDL_Delay(5); } void RenderScreen() { PROFILE("Screen Renderer"); for(int r=0; r<100; r++) { for(int c=0; c<100; c++) { PROFILE("Tile Renderer"); RenderTile(); } } } int factorial(int num) { if(num <= 1) { return 1; } else { return (num * factorial(num -1)); } } int factorial2(int num) { PROFILE("Iterative Factorial"); int result; int i; result = 1; for (i=num; i>0; i--) { PROFILE("IF Loop"); result *= i; } return (result); } void ProcessGameLogic() { static int num = 1; PROFILE("Game Logic"); //Compute factorial recursively: { PROFILE("Recursive Factorial"); factorial(num); } //Compute factorial iteratively: factorial2(num); } void GameLoop() { SetUpGame(); for(int i=0; i<1000; i++) { RenderScreen(); ProcessGameLogic(); } } int main(int argc, char* argv[]) { //Set up the output handler for the profiler ProfilerLogHandler handler; ProfileSample::SetOutputHandler(&handler); //Create the root sample //Notice how we include it in a set of curly braces so it automatically falls out of scope when we call the game loop: { PROFILE("Game Loop"); GameLoop(); } //Output the results of profiling ProfileSample::Output(); return 0; }