dev-master
9999999-devTool to compare different functions in PHP
MIT
Tool to compare different functions in PHP
Tool to compare different functions in PHP, (*1)
Via Composer, (*2)
composer require lavoiesl/php-benchmark
add('md5', function() { return md5('test'); }); $benchmark->add('sha1', function() { return sha1('test'); }); $benchmark->run(); ?>
You can run $benchmark->run(false)
to get results without any output, (*3)
Memory usage is monitored using register_tick_function
but this does not do a good job at analysing small statements since the memory gets cleaned too quickly., (*4)
A simple trick is the return the value, the AbstractTest
stores it temporarily., (*5)
To ensure proper tick analysis, use declare(ticks = 1);
as early as possible., (*6)
See the memory test., (*7)
Running tests 3000 times. Testing 2/2 : sha1 Test Time Time (%) Memory Memory (%) md5 1304 ms 0 B sha1 2077 ms 59 % 0 B
By default, Benchmark will try to find an optimal number of runs so that each test takes a maximum of 2 seconds., (*8)
You can change this by forcing it with $benchmark->setCount($n)
or change the time with $benchmark->guessCount($max_seconds)
., (*9)
You can extend AbstractTest
and provide your own wrapper., (*10)
For an example of this, see the command test and the corresponding class., (*11)
A full example can be seen here: https://github.com/lavoiesl/php-cache-comparison, (*12)
Tool to compare different functions in PHP
MIT