Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Monday, 15 October 2007

Code for simple PHP timer script

<?php

// Simple timer script


function timeStamp() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}

$startTime = timeStamp();

// Do some things here - i'm just sleeping for a bit
usleep(150000);

// get the split time
$splitTime1 = timeStamp();

// round to 4 dec places, unless you want to be crazy accurate
$splitTime = round($splitTime1 - $startTime,4);
echo "Split Time: ".$splitTime." seconds.";

// Do some more things here
usleep(500000);
$endTime = timeStamp();
$totalTime = round($endTime - $startTime,4);
echo "End Time: ".$totalTime." seconds.";

?>