![QLCDnumberShowMillisecondsTime[1]](http://netporadnik.wkom.pl/wp-content/uploads/2013/12/QLCDnumberShowMillisecondsTime1-300x105.png)
Jak poprawnie użyć microtime() do mierzenia czasu wykonywania skryptu przedstawia listing poniżej:
<?php $stoper_start = microtime(true); // start pomiaru //mierzony skrypt //////////////////////// usleep(1000); ///////////////////////////////////////// $stoper_stop = microtime(true); //koniec pomiaru echo bcsub($stoper_stop, $stoper_start, 4); // wynik np 1.0123 sekundy ?>
http://php.net/manual/pl/function.microtime.php
http://www.php.net/manual/pl/function.bcsub.php
edit:
<?php
// funkcja zlicza od poczatku
//pierwsze uzycie to jest start, kazde kolejne uzycie podaje roznice od startu
function stoper()
{
static $stoper = null;
if ($stoper === null) {
$stoper=microtime(true);
} else {
$akt=microtime(true);
$wynik = bcsub($akt, $stoper, 4);
return $wynik;
}
};
stoper();usleep(100);
echo stoper();usleep(20000);
echo "<br>".stoper();usleep(100);
echo "<br>".stoper();usleep(100);
echo "<br>".stoper();usleep(100);
echo "<br>".stoper();usleep(100);
echo "<br>".stoper();
?>
<?php
// funkcja zlicza miedzy uzyciami
//pierwsze uzycie to jest start, kazde kolejne uzycie podaje roznice od poprzedniego uzycia
function stoper()
{
static $stoper = null;
if ($stoper === null) {
$stoper=microtime(true);
} else {
$akt=microtime(true);
$wynik = bcsub($akt, $stoper, 4);
$stoper = $akt;
return $wynik;
}
};
stoper();usleep(100);
echo stoper();usleep(20000);
echo "<br>".stoper();usleep(100);
echo "<br>".stoper();usleep(100);
echo "<br>".stoper();usleep(100);
echo "<br>".stoper();usleep(100);
echo "<br>".stoper();
?>





przy declare(strict_types=1);
trzeba użyć zmiany typów dla bcsub (przyjmuje string):
(string)$stoper_stop……