TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   what is the purpose of microtime() ? (http://www.talkphp.com/general/3579-what-purpose-microtime.html)

sarmenhb 11-09-2008 02:21 AM

what is the purpose of microtime() ?
 
i was looking at the php help page and found this script below, apparently its supposed to be a timer.. but i did a echo of microtime and found a bunch of gibberish float values. whats its purpose?? thanks

Code:


<?php
$time_start = microtime(true);

// Sleep for a while
usleep(100);

$time_end = microtime(true);
$time = $time_end - $time_start;

echo "Did nothing in $time seconds\n";
?>


martins256 11-09-2008 08:59 AM

You can use it for benchmarking. Do something like this:
Code:

<?php
//put this at the top of your script
$time_start = microtime(true);

// here should be all your php stuff
usleep(100);


//finally get the time php needed to execute everything.
$time_end = microtime(true);
$time = $time_end - $time_start;

echo "Did nothing in $time seconds\n";
?>

If you want something better for benchmarking try xdebug.

ReSpawN 11-09-2008 03:03 PM

I always make my own microtime generator to generate total query time, clear time, fetch time, function times, load times, execution times ect. ;-)


All times are GMT. The time now is 05:39 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0