WolfRage Posted July 20, 2009 Share Posted July 20, 2009 Ok I made a post yesterday but did not get an answer that made sense, so I am going a little deeper this time. microtime() defines a string as msec and sec. But the msec portion is 8 digits long after the decimal for instance 0.52049300. Yet there are only 1,000,000 microseconds in a second. The zero never gets filled so I assume that it is the representation of a second. So what does 0.52049300 mean? Is that a split time of a microsecond? Or is it a larger measure of time? Quote Link to comment https://forums.phpfreaks.com/topic/166635-solved-msec-is-it-really/ Share on other sites More sharing options...
mattal999 Posted July 20, 2009 Share Posted July 20, 2009 Isn't that just a decimal representation of 1,000,000 microseconds? Let me explain in numbers: <?php $msec = 0.52049300; $realmsec = 0.52049300 * 1000000; // I think. This may be miles off the real answer. ?> That's how I see it anyway. Don't see any other way it could work. Quote Link to comment https://forums.phpfreaks.com/topic/166635-solved-msec-is-it-really/#findComment-878679 Share on other sites More sharing options...
ignace Posted July 20, 2009 Share Posted July 20, 2009 It returns the the time passed since the unix epoch in seconds and microseconds. The total time passed since the unix epoch is secs + msecs. Don't know if this has something to do with it but: In the old days they didn't have something like float because those computers couldn't store such long formats therefor they kept it in strings performed some string operation to retrieve both the numbers before the decimal point and the numbers after the decimal point as an integer added some math performed the calculation all within that tiny space and added it back together as a string and displayed it to screen. They even add to store subcalculations in a string format because they lacked space. Quote Link to comment https://forums.phpfreaks.com/topic/166635-solved-msec-is-it-really/#findComment-878688 Share on other sites More sharing options...
WolfRage Posted July 20, 2009 Author Share Posted July 20, 2009 Yeah I pretty much was able to read that. But why is msec represented by a decimal with 8 digits after it? Why when there are only 1,000,000 microseconds in a second are there 8 digits? Is the computer taking split microseconds into consideration? I want a definitive answer not just guesses. I am trying to time as precisely as is possible, but this part does not make sense. Quote Link to comment https://forums.phpfreaks.com/topic/166635-solved-msec-is-it-really/#findComment-878692 Share on other sites More sharing options...
ignace Posted July 20, 2009 Share Posted July 20, 2009 Yeah I pretty much was able to read that. But why is msec represented by a decimal with 8 digits after it? Why when there are only 1,000,000 microseconds in a second are there 8 digits? Is the computer taking split microseconds into consideration? I want a definitive answer not just guesses. I am trying to time as precisely as is possible, but this part does not make sense. print microtime() . '<br>'; print microtime(true);//your definitive answer Quote Link to comment https://forums.phpfreaks.com/topic/166635-solved-msec-is-it-really/#findComment-878700 Share on other sites More sharing options...
WolfRage Posted July 20, 2009 Author Share Posted July 20, 2009 So if you guys are correct in your assumptions then this should be dead on everytime as far as measuring down to the last unit of measurement capable by the microtime function. <?php //Timer $start=explode(' ',microtime()); //execute information here. $finish=explode(' ',microtime()); if($start[1]===$finish[1]) { $start=explode('.',$start[0]); $finish=explode('.',$finish[0]); $diff=$finish[1]-$start[1]; if(($start[0]!=='0') || ($finish[0]!=='0')) { echo 'We have encountered an exception that was not thought to be possible.'; exit; } } else { $start=explode('.',$start[0]); $finish=explode('.',$finish[0]); $finish[1]=$finish[1]+100000000; $diff=$finish[1]-$start[1]; if(($start[0]!=='0') || ($finish[0]!=='0')) { echo 'We have encountered an exception that was not thought to be possible.'; exit; } } echo 'Time Difference: '.$diff; echo '<br />'; echo 'Finish Time: '.$finish[1]; echo '<br />'; echo 'Start Time: '.$start[1]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/166635-solved-msec-is-it-really/#findComment-878701 Share on other sites More sharing options...
WolfRage Posted July 20, 2009 Author Share Posted July 20, 2009 Well so far from running this code many times it seems that the last two digits are never filled out by the computer. Thus it is only measuring down to the microsecond any ways. Sorry if i pissed any one off, but I wanted to know if I was right in my assumption too, just one of those things you have to know. Thank you for your help! Quote Link to comment https://forums.phpfreaks.com/topic/166635-solved-msec-is-it-really/#findComment-878707 Share on other sites More sharing options...
WolfRage Posted July 20, 2009 Author Share Posted July 20, 2009 Not sure if any one cares but this is the basic concept that I came up with to report microseconds only. That is so long as we are correct, which I think we are. <?php //Timer $start=explode(' ',microtime()); //execute information here. $finish=explode(' ',microtime()); if($start[1]===$finish[1]) { $start=explode('.',$start[0]); $finish=explode('.',$finish[0]); $diff=$finish[1]-$start[1]; if(($start[0]!=='0') || ($finish[0]!=='0')) { echo 'We have encountered an exception that was not thought to be possible.'; exit; } } else { $start=explode('.',$start[0]); $finish=explode('.',$finish[0]); $finish[1]=$finish[1]+100000000; $diff=$finish[1]-$start[1]; if(($start[0]!=='0') || ($finish[0]!=='0')) { echo 'We have encountered an exception that was not thought to be possible.'; exit; } } $diff=substr($diff,0,strlen($diff)-2); echo 'Time Difference: '.$diff.' microseconds.'; echo '<br />'; echo 'Finish Time: '.$finish[1]; echo '<br />'; echo 'Start Time: '.$start[1]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/166635-solved-msec-is-it-really/#findComment-878725 Share on other sites More sharing options...
Daniel0 Posted July 20, 2009 Share Posted July 20, 2009 You can also just do something like: $start = microtime(true); sleep(2); $end = microtime(true) - $start Same thing really. That parameter was added in PHP5. Quote Link to comment https://forums.phpfreaks.com/topic/166635-solved-msec-is-it-really/#findComment-878732 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.