microtime() and floating point arithmetics

apache, mysql, performance, php

Solution

microtime — Return current Unix timestamp with microseconds

mixed microtime ([ bool $get_as_float = false ] )

do instead:

$time = microtime(true);
echo microtime(true) - $time;

And result will be in seconds. Check this(Manual):

'time1' => float 1360860136.6731

'time2' => float 1360860136.6732 and

'time2' - 'time1' = 9.9897384643555E-5 i.e. 0.000099897384643555 (not 0.0001)

PHP typically uses the IEEE 754 double precision format. Rational numbers that are exactly representable as floating point numbers in base 10, like 0.1 or 0.7, do not have an exact representation as floating point numbers in base 2

Problem

I created a simple website which grabs articles from a MySQL database. I used PHP `microtime(true)` function to calculate the time of the interpretation. At the top of my PHP script I used : ``` $time = microtime(true); ``` And at the bottom of the page I used the following code : ``` echo microtime(true) - $time; ``` When I refresh my webpage with those statements at the top and bottom of my script. It always echos out a value around (`0.0355005264282`; just an instance). That is the time that took to interpret my PHP page. As the PHP manual says (http://php.net/manual/en/function.microtime.php), `microtime(true)` returns the current unix time stamp in microseconds. A microsecond `is one millionth of` a second. So, (for instance): ``` 0.03 microseconds = 1/1,000,000 * 0.03 seconds 0.03 microseconds = 0.000,000,03 seconds ``` So the time took to interpret a PHP webpage which uses MySQL is around `0.000,000,03` seconds. My Questions are : Is this `microtime(true)` is telling the truth about the interpretation time ? If it's true, It's wonderful, because I won't have to worry too much about performance anymore. I am using XAMPP on Windows

Original source