Benchmark_Profiler – About Benchmark_Profiler

About Benchmark_Profiler

This class behaves mostly like Benchmark_Timer with the exception that you are allowed to specify the beginning and end of sections within the code to be profiled. sections are different from markers (markers) don't have ends in the sense that they are stateful and remember how many times they have been entered.

Timing information is recorded at the beginning and end of the code to be profiled and at the beginning and end of every section everytime it is encountered. An example follows.

Benchmark_Profiler in manual mode


require_once 'Benchmark/Profiler.php';

$profiler = new Benchmark_Profiler;

wasteTime() {
$j 2;
    for (
$i 0$i 100$i++) {
$j $j 10;

myFunction() {

// Manual mode, so start manually


// Manual mode, stop and display results


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.

Results of a test run of Benchmark_Profiler

Section             Total Ex Time         Netto Ex Time         #Calls    Percentage
myFunction          5.8174133300781E-5    5.8174133300781E-5    2          17.22%
Global              0.00033783912658691   0.00027966499328613   1         100.00%

As you can see, the default output may not be too helpful. You can obtain detailed section by section profiling information in manual mode through methods like getSectionInformations() and getAllSectionsInformations(). Refer to the API documentation for more information.

About Benchmark_Timer (Previous) About Benchmark_Iterate (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.