As mentioned before, this class simply records the time taken for a particular snippet of code to execute. In the automatic mode, this means the code remaining after the class's instantiation. In manual mode, the snippet of code to be timed is specified between calls to the start() and stop() methods of the class.
Additionally, you may specify markers between the snippet of code to be timed. The timing information is recorded wherever markers are defined.
An example will make this clear.
Example 35-1. Benchmark_Timer in automatic mode
The example above will generate an output as shown below when run with the PHP CLI SAPI. Running it with the Apache SAPI will produce the same results, but formatted as HTML.
Example 35-2. Results of a test run of Benchmark_Timer
In most cases however, you would like to do something with that information. When you run the timer in manual mode, you can obtain the results as an associative array using the getProfiling() method. To display the information (as shown above) use the display() method. More information on the methods that Benchmark_Timer implements is available in the API Documentation.