Newsgroups: php.internals,php.internals.win Path: news.php.net Xref: news.php.net php.internals:77014 php.internals.win:1054 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7046 invoked from network); 1 Sep 2014 18:36:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Sep 2014 18:36:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=php_lists@realplain.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=php_lists@realplain.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain realplain.com does not designate 216.33.127.82 as permitted sender) X-PHP-List-Original-Sender: php_lists@realplain.com X-Host-Fingerprint: 216.33.127.82 mta31.charter.net Solaris 10 1203 Received: from [216.33.127.82] ([216.33.127.82:39048] helo=mta31.charter.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 77/90-03336-2BCB4045 for ; Mon, 01 Sep 2014 14:36:34 -0400 Received: from imp10 ([10.20.200.15]) by mta31.charter.net (InterMail vM.8.01.05.02 201-2260-151-103-20110920) with ESMTP id <20140901183631.EESK6769.mta31.charter.net@imp10>; Mon, 1 Sep 2014 14:36:31 -0400 Received: from mtaout006.msg.strl.va.charter.net ([68.114.190.31]) by imp10 with smtp.charter.net id lucX1o0030h5dSU05ucXRv; Mon, 01 Sep 2014 14:36:31 -0400 Received: from impout002 ([68.114.189.17]) by mtaout006.msg.strl.va.charter.net (InterMail vM.9.00.010.00 201-2473-137) with ESMTP id <20140901183631.JUKT15915.mtaout006.msg.strl.va.charter.net@impout002>; Mon, 1 Sep 2014 13:36:31 -0500 Received: from pc1 ([96.35.251.86]) by impout002 with charter.net id lucW1o00G1sc0so01ucWUQ; Mon, 01 Sep 2014 13:36:31 -0500 X-Authority-Analysis: v=2.1 cv=W6e2VHmk c=1 sm=1 tr=0 a=Is5gsZaFXO8aPum+t7Tz+g==:117 a=Is5gsZaFXO8aPum+t7Tz+g==:17 a=hOpmn2quAAAA:8 a=h-BQEdXfgq4A:10 a=CT7g7-v8860A:10 a=WUgRJF_wMoEA:10 a=8nJEP1OIZ-IA:10 a=BCPeO_TGAAAA:8 a=yMhMjlubAAAA:8 a=NEAV23lmAAAA:8 a=HrpT7aBciiaiiim6-DkA:9 a=wPNLvfGTeEIA:10 Message-ID: To: , Cc: "Pierre Joye" , "Anatol Belski" Date: Mon, 1 Sep 2014 13:36:30 -0500 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Subject: [PATCH] Microsecond resolution and accuracy on Windows From: php_lists@realplain.com ("Matt Wilmas") Hi all! I'm back after several years, and will have a few more changes for Windows, at least. (It was CVS back then, so I still have to figure some things out... Just had to edit files on Github site. :-/) Anyway, this patch is for microtime, etc. on Windows XP-7. In March 2013, the fix for bug #64370 reduced the resolution to 1/64 or 1/100 of a second or so -- hardly "micro" time. :*( See also bugs #64633 and #65626. The highest resolution time function available before Windows 8 has simply been used by itself since then. High-resolution Performance Counters were always used until then, but in a way that may become inaccurate and error-prone on some Windows+(virtual) hardware combinations. One problem with the long-standing previous Performance Counter implementation is that it tried to be monotonic (always increasing). But gettimeofday() IS supposed to be affected by changes in system time. Another problem was assuming that Performance Counters would track at a nearly-perfect rate with the real clock even without system time changes. The solution to have high-resolution like the past, and accuracy like now (after #64370 fix) is fairly simple and straightforward: Use Performance Counters, but check that the value is within "range" of the real, current time! With this implementation, you get high-resolution at least over short periods (e.g. when it matters) AND accuracy over a longer time between calls (e.g. won't notice few milliseconds of lost resolution), with no buggy/incorrect times. (It seems there *could* be a Counter synchronization issue between multiple cores/processors on *some* hardware on *XP*. I don't think this is a concern, nor related to previous bugs? http://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx#qpc_support_in_windows_versions ) It's much more optimized than what's there now, and slightly over the old implementation. Not sure if I should give the saved patch link, or the "live compare" (?) on Github, so I'll do both for now: http://realplain.com/php/microtime_5_4.diff https://github.com/matt-moo/php-src/compare/PHP-5.4.diff Against 5.4 since that's what I quickly worked on so it's ready for the next 5.4 release (Stas?). (Although I guess we're supposed to change the oldest branch usually?) What do you think? Questions or comments? Thanks, Matt