note 53810 deleted from function.microtime by nlopess
| From: | nlopess@php.net | Date: | Tue, 14 Jun 2005 09:35:28 +0000 |
| Subject: | note 53810 deleted from function.microtime by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-90399@lists.php.net to get a copy of this message | ||
Note Submitter: nofulfillment at numbinside dot net
----
Hmm...perhaps their is some speed loss to unluckypixie's method...anyone want to check this
out?
On a side note, personally, the way I'm doing it for cross-compatibility between PHP4 and PHP5
is by simply doing a version compare. I mean, compiled code is always faster than interpreted.
.::My method::.
<?php
/*
* Copyright 2005, Wesley Spikes.
* nofulfillment@numbinside.net
* http://nothingcanfulfill.numbinside.net
*
* Freely distributable. My only request is that you
* credit me in the source code (by not removing this
* copyright notice) and email me telling me that you're
* using it (I'd love to know that my code is being put to
* good use)!
* As usual, there are no warranties, express or implied
* alike, as to ...blah, blah, blah. (Where's the vodka...
* legal shit drives one insane!)
*
* INFO: a new twist on the getmicrotime() function. if
* we're using a version of php that supports the new
* get_as_float parameter (PHP>5.0.0) then use the
* newly supported paramater as built-in functions are
* generally faster. otherwise, use the old method of
* splitting the two parts and adding them togeather.
*
* As a bit of advertising bull...I'm currently in the
* process of creating a page on my new website for
* code sniplets like this (that would make number
* 1,000,001 on the internet).
*/
if (version_compare("5.0.0",phpversion(),"<=")==1) {
function getmicrotime() {
return microtime(1);
}
} else {
function getmicrotime() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
}
?>
The above code will create a function which returns a float containing the current
``microtime''. Syntax as follows: float getmicrotime( )
-Wes