Quick command line test

I would like to compare a PHP script, but this applies equally to everything that can be run from the command line.

With bash, is there an easy way to evaluate the script, i.e. execute the command several times and how long will it take?

+6
source share
2 answers

At the command line, you can:

$ time php foobar.php 

Here time is a built-in bash.

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 manually.

+14
source

If you just want to check out the PHP script, why not just write a unit test for it. How:

 <?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 } ?> 
+1
source

Source: https://habr.com/ru/post/920843/


All Articles