3

I'm trying to profile my Kohana project using Profiler. I'm on XAMPP on Windows with php 5.5.3. On this version of PHP I'm getting 0.000000 sec. execution time for main request, find_file() or database calls. Same behavior with PHP 5.4.19.

If I move the project to XAMPP with PHP 5.3 everything works as expected - single database query takes something around 0.00012-0.00014 sec., etc. I suspect something has changed in microtime(true) function since 5.3 version. If I'm measuring rand(0, 9999) with 10000 iterations with the simple time calculation:

$time_start = microtime(true);
for($i=0; $i<10000; $i++) {
    rand(0, 9999);
}
$time_end = microtime(true);
$time = $time_end - $time_start;

I still getting the same times before and after function call, so execution time equals to 0, which is not possible of course.

Is there any way to fix this behavior on PHP 5.4 or 5.5 on Windows to get more precise timings? thanks!

Kanstantsin K.
  • 512
  • 4
  • 17
  • Doesn't seem to be 0 for me: http://sandbox.onlinephpfunctions.com/code/c31c2915fa1aa0aa389c1db444e3d634a87ed4e0 – Hanky Panky Sep 19 '13 at 08:12
  • Thanks, but I'm not sure that onlinephpfunctions.com is running on Windows. – Kanstantsin K. Sep 19 '13 at 08:20
  • let me check somewhere else – Hanky Panky Sep 19 '13 at 08:21
  • 1
    ```Microsoft Windows [Version 6.2.9200] (c) 2012 Microsoft Corporation. All rights reserved. C:\Users\Mark>php \Projects\014.php float(0.0026249885559082) C:\Users\Mark>php52 \Projects\014.php float(0.0044069290161133) C:\Users\Mark>php53 \Projects\014.php float(0.0048799514770508) C:\Users\Mark>php54 \Projects\014.php float(0.0027458667755127) C:\Users\Mark>php55 \Projects\014.php float(0.002194881439209) ``` – Mark Baker Sep 19 '13 at 08:23
  • Thanks, Mark. Are you on 64 or 32 bit version? – Kanstantsin K. Sep 19 '13 at 08:35
  • 64-bit Windows 8; all versions of PHP are 32 bit thread-safe – Mark Baker Sep 19 '13 at 08:57
  • OK, I've tried to download from php.net binaries of different versions of PHP and run that test - code woks fine on 5.3.8 and before (0.0037951469421387), but 5.3.27 and up - 0. I'm on Win 7 32 bit. Really strange. – Kanstantsin K. Sep 19 '13 at 11:18
  • It seems like the issue begins in php 5.3.24: `F:\>php_53x\php -v PHP 5.3.23 (cli) (built: Mar 14 2013 23:00:57) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies F:\>php_53x\php \test.php 0.0038888454437256` and `F:\>php_53x\php -v PHP 5.3.24 (cli) (built: Apr 10 2013 18:38:43) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies F:\>php_53x\php \test.php 0 ` It may be related to bug #64370... – Kanstantsin K. Sep 19 '13 at 12:21

1 Answers1

1

Looking on the php source code

if(6 == EG(windows_version_info).dwMajorVersion && 2 >= EG(windows_version_info).dwMinorVersion) {
        GetSystemTimePreciseAsFileTime(&ft); /* highest possible resolution <1us */
    } else {
        GetSystemTimeAsFileTime(&ft);   /* 100ns blocks since 01-Jan-1641 */
    }

it seems like Windows 8 has more precise timing function so that's why it's not repeatable on that version.

I was able to fix this problem by using calibration tool from http://windowstimestamp.com.

Thanks everyone for the answers!

Kanstantsin K.
  • 512
  • 4
  • 17