PHP Class Lavoiesl\PhpBenchmark\Benchmark

Show file Open project: lavoiesl/php-benchmark Class Usage Examples

Public Methods

Method Description
add ( string $name, Closure $closure ) : SimpleTest Utility method to create tests on the fly You may chain the test:
addTest ( AbstractTest $test )
formatResults ( array $results ) : array Format the results, rounding numbers, showing difference percentages and removing a flat time based on the benchmark overhead
guessCount ( float $max_seconds ) : integer Average the guessCount of each test, determining the best n
outputTable ( array $lines, integer $padding = 3 ) Output results in columns, padding right if values are string, left if numeric
run ( $output = true )
setCount ( $n )

Private Methods

Method Description
warmup ( ) Runs an empty test to determine the benchmark overhead and run each test once

Method Details

add() public method

Utility method to create tests on the fly You may chain the test:
public add ( string $name, Closure $closure ) : SimpleTest
$name string
$closure Closure function to execute
return SimpleTest

addTest() public method

public addTest ( AbstractTest $test )
$test AbstractTest

formatResults() public method

Format the results, rounding numbers, showing difference percentages and removing a flat time based on the benchmark overhead
public formatResults ( array $results ) : array
$results array array($name => array('time' => 1.0))
return array array(array('Test' => $name, 'Time' => '1000 ms', 'Perc' => '100 %'))

guessCount() public method

Average the guessCount of each test, determining the best n
public guessCount ( float $max_seconds ) : integer
$max_seconds float
return integer

outputTable() public static method

Output results in columns, padding right if values are string, left if numeric
public static outputTable ( array $lines, integer $padding = 3 )
$lines array array(array('Name' => 'Value'));
$padding integer space between columns

run() public method

public run ( $output = true )

setCount() public method

public setCount ( $n )