Mantis - Quercus
Viewing Issue Advanced Details
1119 minor always 05-17-06 12:02 05-19-06 13:19
koreth  
ferg  
normal  
closed 3.0.20  
fixed  
none    
none 3.0.20  
0001119: microtime() is only millisecond-accurate, is formatted incorrectly (w/patch)
We use microtime() to do some internal profiling of database queries and communication with backend servers. It appears that Quercus' microtime() is broken in two ways: it is not microsecond-accurate (since it's based on System.currentTimeMillis()) and its string output is in the wrong format (should be ".012345 6789" instead of "12345 67890".)

Here's a patch. I did the initial divide by 1000 because I found it hard to visually count all the zeros in the subsequent division and modulo operations.


--- resin-3.0.s060516/modules/quercus/src/com/caucho/quercus/lib/DateModule.java2006-05-10 19:50:42.000000000 -0700
+++ old/060516/resin-3.0.s060516/modules/quercus/src/com/caucho/quercus/lib/DateModule.java 2006-05-16 18:12:45.000000000 -0700
@@ -603,13 +603,13 @@
    */
   public static Value microtime(@Optional boolean getAsFloat)
   {
- long now = Alarm.getCurrentTime();
+ long now = Alarm.getExactTimeNanoseconds() / 1000;
 
     if (getAsFloat) {
- return new DoubleValue((double) now / 1000.0);
+ return new DoubleValue((double) now / 1000000.0);
     }
     else {
- return new StringValueImpl((now % 1000 * 1000) + " " + (now / 1000));
+ return new StringValueImpl((now % 1000000) / 1000000.0 + " " + (now / 1000000));
     }
   }

Notes
(0001159)
ferg   
05-19-06 13:19   
php/1903