Mantis Bugtracker
  

Viewing Issue Advanced Details Jump to Notes ] View Simple ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0002186 [Quercus] minor always 11-18-07 15:06 11-19-07 20:16
Reporter koreth View Status public  
Assigned To nam
Priority normal Resolution fixed Platform
Status closed   OS
Projection none   OS Version
ETA none Fixed in Version 3.1.4 Product Version 3.1.4
  Product Build
Summary 0002186: microtime() is only millisecond-accurate
Description I was doing some performance tests in compiled mode and noticed my run times had much less noise than expected:

<?php
$start_time = microtime(true);
include_once $_SERVER['PHP_ROOT'].'/lib/core/init.php';
print "elapsed = " . (microtime(true) - $start_time) . " sec\n";

elapsed = 0.006000041961669922 sec
elapsed = 0.003000020980834961 sec
elapsed = 0.0029997825622558594 sec
elapsed = 0.003000020980834961 sec
elapsed = 0.003000020980834961 sec
elapsed = 0.003000020980834961 sec
elapsed = 0.003000020980834961 sec
elapsed = 0.003000020980834961 sec
elapsed = 0.002000093460083008 sec
elapsed = 0.003000020980834961 sec

The Zend PHP interpreter is much more accurate. This lack of precision makes it much harder to do meaningful internal performance monitoring in a PHP app -- and in particular, to benchmark Quercus versus vanilla PHP and identify their respective bottlenecks -- since most operations will appear to take either no time at all or 1 millisecond depending on whether they happen to straddle a millisecond boundary.
Steps To Reproduce
Additional Information
Attached Files  patch.txt [^] (1,509 bytes) 11-18-07 15:41

- Relationships

- Notes
(0002505)
koreth
11-18-07 15:37

Simpler test case:

<?php
$a = microtime(true);
for ($i = 0; $i < 10; $i++) ;
$b = microtime(true);
print ($b - $a) . "\n";

You'll get "0.0" from Quercus nearly every time you run this, and various small numbers from vanilla PHP.
 
(0002506)
koreth
11-18-07 15:45

One possible fix attached; on Linux, at least, System.nanoTime() actually returns the nanosecond-accurate system time. Since that's not guaranteed by the JDK spec I test to see if it's true, and if not, fall back to the old behavior.

A more robust implementation would probably try to figure out the offset between nanoTime() and currentTimeMillis()*1000000, but this is at least better than the current situation.
 
(0002511)
nam
11-19-07 20:16

php/1903

System.nanoTime() returns the system time for Linux machines
System.nanoTime() returns some arbitrary timer time for Windows machines

microtime() changed to return System.nanoTime() for non-windows machines, and System.currentTimeMillis() for windows
 

- Issue History
Date Modified Username Field Change
11-18-07 15:06 koreth New Issue
11-18-07 15:37 koreth Note Added: 0002505
11-18-07 15:41 koreth File Added: patch.txt
11-18-07 15:45 koreth Note Added: 0002506
11-19-07 20:12 nam Status new => assigned
11-19-07 20:12 nam Assigned To  => nam
11-19-07 20:16 nam Status assigned => closed
11-19-07 20:16 nam Note Added: 0002511
11-19-07 20:16 nam Resolution open => fixed
11-19-07 20:16 nam Fixed in Version  => 3.1.4


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
34 total queries executed.
28 unique queries executed.
Powered by Mantis Bugtracker