I'd like to benchmark a PHP script, but this would equally apply to anything that can be run from the command line.
Using bash is there a simple way to benchmark a script, i.e. run a command multiple times and time how long it takes?
In command line, you can:
$ time php foobar.php
Here time
is a bash built-in.
For multiple runs:
$ time for a in {1..10}; do php foobar.php; done
real 0m13.042s
user 0m0.021s
sys 0m0.044s
However, you need to calculate the average time by hand.
If all you want is to benchmark a PHP script why not just write a unit test for it. Like:
<?php
function test() {
require 'my_script_to_test.php';
}
for ($i = 0; $i < 1000; $i++) {
$time = microtime(true);
test();
$time = microtime(true) - $time;
echo 'test '.$i.': '.$time;
// and then you can also average time and w/e
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With