I want to know what is the best way to benchmark my PHP scripts. Does not matter if a cron job, or webpage or web service.
I know i can use microtime but is it really giving me the real time of a PHP script?
I want to test and benchmark different functions in PHP that do the same thing. For example, preg_match
vs strpos
or domdocument
vs preg_match
or preg_replace vs str_replace`
Example of a webpage:
<?php
// login.php
$start_time = microtime(TRUE);
session_start();
// do all my logic etc...
$end_time = microtime(TRUE);
echo $end_time - $start_time;
This will output: 0.0146126717 (varies all the time - but that is the last one I got). This means it took 0.015 or so to execute the PHP script.
Is there a better way?