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.";

?>

1 comment:

Derek said...

This is a wonderful help. Perhaps you are a good Samaritan and would be willing to help me figure out a modification of this script for another application. Let me know if this would be possible.