This package is based on http://pear.php.net/package/Benchmark rewritten in modern PHP
Please report all new issues
Provides timing and profiling information.
Install
You can install the library using composer:
$ composer require tveronesi/simple-php-benchmark
How to use
Profiler
Example 1: Automatic profiling start, stop, and output.
<?php
$profiler = new Benchmark\Profiler(true);
function myFunction() {
global $profiler; // don't do this, only for example purposes
$profiler->enterSection('myFunction');
//do something
$profiler->leaveSection('myFunction');
return;
}
//do something
myFunction();
//do more
Example 2: Manual profiling start, stop, and output.
<?php
$profiler = new Benchmark\Profiler();
function myFunction() {
global $profiler; // don't do this, only for example purposes
$profiler->enterSection('myFunction');
//do something
$profiler->leaveSection('myFunction');
return;
}
$profiler->start();
//do something
myFunction();
//do more
$profiler->stop();
$profiler->display();
Benchmark
Example 1: Automatic profiling start, stop, and output.
<?php
$timer = new Benchmark\Timer(true);
$timer->setMarker('Marker 1');
Example 2: Manual profiling start, stop, and output.
<?php
$timer = new Benchmark\Timer();
$timer->start();
$timer->setMarker('Marker 1');
$timer->stop();
$timer->display(); // to output html formated
// AND/OR :
$profiling = $timer->getProfiling(); // get profiler info as associative array
Iterate
Example 1
<?php
$benchmark = new Benchmark\Iterate;
function foo($string) {
print $string . '<br>';
}
$benchmark->run(100, 'foo', 'test');
$result = $benchmark->get();
Example 2
<?php
$benchmark = new Benchmark\Iterate;
class MyClass {
function foo($string) {
print $string . '<br>';
}
}
$benchmark->run(100, 'myclass::foo', 'test');
$result = $benchmark->get();
Example 3
<?php
$benchmark = new Benchmark\Iterate;
class MyClass {
function foo($string) {
print $string . '<br>';
}
}
$o = new MyClass();
$benchmark->run(100, 'o->foo', 'test');
$result = $benchmark->get();