PHP Snippets
timer
Information
(PHP Version >= 4.0.4)Functions used in this snippet: array_sum, microtime, explode, number_format.
Description
float timer([float start,[int num]])
sets a start timer and outputs another timer less start to num decimals.
Snippet
<?php
function timer($start='',$num=8){
if($start === ''){
return array_sum(explode(' ',microtime()));
}else{
return number_format(timer() - $start,$num);
}
}
?>
Example
timer Can be used in the following way:
<?php
$start = timer();
// code to be timed goes here
echo timer($start); // shows elapsed time to 8 decimal places
$start = timer();
// code to be timed goes here
echo timer($start,12); // shows elapsed time to 12 decimal places
?>
Updated on Jul 1st at 4 am.
0 Responses to timer