<?php

$time

=

microtime

();



$timeval

=

substr

(

$time

,

11

).

substr

(

$time

,

1

,

9

);



?>



<?php



function

microtime_used

(

$before

,

$after

) {

return (

substr

(

$after

,

11

)-

substr

(

$before

,

11

))

+(

substr

(

$after

,

0

,

9

)-

substr

(

$before

,

0

,

9

));

}



?>



Of the methods I've seen here, and thought up myself, to convert microtime() output into a numerical value, the microtime_float() one shown in the documentation proper(using explode,list,float,+) is the slowest in terms of runtime.I implemented the various methods, ran each in a tight loop 1,000,000 times, and compared runtimes (and output). I did this 10 times to make sure there wasn't a problem of other things putting a load spike on the server. I'll admit I didn't take into account martijn at vanderlee dot com's comments on testing accuracy, but as I figured the looping code etc would be the same, and this was only meant as a relative comparison, it should not be necessary.The above method took on average 5.7151877 seconds, while a method using substr and simply adding strings with . took on average 3.0144226 seconds. rsalazar at innox dot com dot mx's method using preg_replace used on average 4.1819633 seconds. This shows that there are indeed differences, but for normal use noone is going to notice it.Note that the substr method mentioned isn't quite the one given anonymously below, but one I made based on it:Also worth noting is that the microtime_float() method gets faster, and no less accurate, if the (float) conversions are taken out and the variables are simply added together.Any of the methods that used + or array_sum ended up rounding the result to 2 digits after the decimal point, while (most of) the ones using preg_replace or substr and . kept all the digits.For accurate timing, since floating-point arithmetic would lose precision, I stored microtime results as-is and calculated time difference with this function:For further information, the script itself, etc, see http://edorfaus.xepher.net/div/convert-method-test.php