Contact Us

Banner Text

Profiler Manual

This profiler is intended to be used to identify areas of code that could be optimised in order to improve overall performance of an application. Typically I identify the areas of concern in an application and place profile timers around those sections and focus down to add timers around the areas that are taking the most time and look for ways to optimise those particular areas. The items with the highest percentage time spent are usually the ones that can give the biggest improvements.


Perform profiling to provide the following information

  • Count the number of times a section of code is executed
  • Calculate the total ammount of time spent executing a section of code
  • Permit multiple timers to be set
  • Allow nested timers to such that the parent timers are suspended whilst a child section of code is running.
  • Output a report at the end of execution to show the percentage of time spent on an operation,
  • the number of times the section was run, the overall time spent on the section.


include_once( '');
$prof = new Profiler( profile_flag, trace_flag );

  • Profile_flag = true enables output of the statistical information
  • trace_flag = true enables output of the trace information

$prof->startTimer( "timer_name", "Description" );

  • timer_name is a simple string to name the timer
  • description is an optional string to describe the purpose of the timer in more detail

$prof->stopTimer( "timer_name" );

$prof->printTimers( flag );

  • Output the final report of the processing operation being run. Normally this would be called as one of the last statements on a page.
  • If flag=true is set then the output will be forced even if the profile_flag was set false when the profiler was initialised



If a profile timer is started in a function, it must be stopped prior to exiting that function in order to ensure integrity of the output information.


Example Usage

        $prof = new Profiler( true ); // Output the profile information but no trace

        $prof->startTimer( "initialise" );
        $prof->stopTimer( "initialise" );

        $prof->startTimer( "main_loop" );

        while( $record=get_record() ){
            print_record( $record );

        $prof->stopTimer( "main_loop" );

        $prof->printTimers( true );

        function get_record()
            global $prof;

            $prof->startTimer( "get_record" );
            // Routine to get the record information
            $prof->stopTimer( "get_record" );

        function print_record( $record )
            global $prof;
            // print header information

            $prof->startTimer( "main_print_record" );
            // main print processing
            $prof->stopTimer( "main_print_record" );


If you make any improvements to the code, or just find it useful in helping you optimise the performance of your applications I would appreciate you dropping a note.

© Copyright 2002 Carl Taylor