BigToach.com

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
?>

Added on Jun 23rd at 9 pm by Scott - 0 Comments
Updated on Jul 1st at 4 am.


0 Responses to timer

Name:

Site or Mail:

Comment:

To try to reduce the ammount of spam, please enter the word GOOSE in the following form

Security Code: