Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Jan 23, 2012, 4:02 PM

Post #1 of 16 (127 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows

New submission from STINNER Victor <victor.stinner [at] haypocalc>:

Python implements time.time() using gettimeofday() which has only a resolution of 1 microsecond because it uses the timeval structure which is only able to store microseconds.

Attached patch changes _PyTime_gettimeofday() to make it uses the timespec structure (which has a resolution has 1 nanosecond) and use GetSystemTimeAsFileTime() on Windows. So time.time() has a theorical resolution 10 times better than currently.

----------
files: timespec.patch
keywords: patch
messages: 151865
nosy: belopolsky, haypo
priority: normal
severity: normal
status: open
title: Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows
versions: Python 3.3
Added file: http://bugs.python.org/file24305/timespec.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jan 23, 2012, 4:11 PM

Post #2 of 16 (81 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows [In reply to]

STINNER Victor <victor.stinner [at] haypocalc> added the comment:

Oops, my first patch contains an unrelated change for Windows.

New patch fixes this bug, and change time_clock() to reuse time_time() if time_clock() fails to get the CPU frequency (unlikely) because it has a better resolution than clock().

----------
Added file: http://bugs.python.org/file24306/timespec-2.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jan 23, 2012, 4:11 PM

Post #3 of 16 (74 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows [In reply to]

Changes by STINNER Victor <victor.stinner [at] haypocalc>:


Removed file: http://bugs.python.org/file24305/timespec.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jan 23, 2012, 5:27 PM

Post #4 of 16 (79 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows [In reply to]

STINNER Victor <victor.stinner [at] haypocalc> added the comment:

See also #11457 for discussion on nanosecond resolution and a potential new type to avoid loose of resolution of the Python float type (IEEE binary64).

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jan 23, 2012, 8:11 PM

Post #5 of 16 (71 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows [In reply to]

Changes by Ross Lagerwall <rosslagerwall [at] gmail>:


----------
nosy: +rosslagerwall

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jan 24, 2012, 2:48 AM

Post #6 of 16 (70 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows [In reply to]

Amaury Forgeot d'Arc <amauryfa [at] gmail> added the comment:

GetSystemTimeAsFileTime() represent durations as multiple of 100ns, unfortunately its value is only updated every 15ms or so. Precision is not accuracy...

----------
nosy: +amaury.forgeotdarc

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jan 24, 2012, 3:22 AM

Post #7 of 16 (68 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows [In reply to]

STINNER Victor <victor.stinner [at] haypocalc> added the comment:

> GetSystemTimeAsFileTime() represent durations as multiple of 100ns, unfortunately its value is only updated every 15ms or so.  Precision is not accuracy...

It is possible to improve the accuracy of this clock using the
undocumented NtSetTimerResolution() function:
http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/Time/NtSetTimerResolution.html

There are applications using this undocumented function. For example:
http://www.lucashale.com/timer-resolution/

See also the timeBeginPeriod() function:
http://msdn.microsoft.com/en-us/library/ms713413%28VS.85%29.aspx

The user may have a special hardware (and its driver) or a special
softwared (ntpd?) with a better accuracy.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jan 24, 2012, 3:49 AM

Post #8 of 16 (68 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows [In reply to]

Amaury Forgeot d'Arc <amauryfa [at] gmail> added the comment:

NtSetTimerResolution is a system-wide change, and may have impact on other running applications. It may be an option to set it during the execution of profile.run() for example, but I would not enable it just to call time.clock().

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jan 24, 2012, 5:17 AM

Post #9 of 16 (68 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows [In reply to]

STINNER Victor <victor.stinner [at] haypocalc> added the comment:

> NtSetTimerResolution is a system-wide change, and may have impact on other running applications.  It may be an option to set it during the execution of profile.run() for example, but I would not enable it just to call time.clock().

I was not proposing to call, but it was trying to say that under
certain circumstances, you may have a better resolution than 15 ms.
Python should not limit the resolution if the OS provides a better
resolution.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jan 26, 2012, 1:51 PM

Post #10 of 16 (64 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows [In reply to]

STINNER Victor <victor.stinner [at] haypocalc> added the comment:

Using the patch of #13882, I realize that time.time() has a resolution of 1 millisecond (10^-3) and not of a microsecond (10^-6) on Windows! Windows doesn't provide gettimeofday(). Using GetSystemTimeAsFileTime() would provide a much better resolution!

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jan 29, 2012, 5:38 PM

Post #11 of 16 (45 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows [In reply to]

STINNER Victor <victor.stinner [at] haypocalc> added the comment:

Two articles (Microsoft and IBM) about high resolution time on Windows:
http://msdn.microsoft.com/en-us/magazine/cc163996.aspx
http://www.ibm.com/developerworks/library/i-seconds/

I installed the Windows port of the NTP daemon:
http://www.meinberg.de/english/sw/ntp.htm

Using the NTP daemon, the resolution is 1 ms instead of 15 ms (on Windows Seven). It looks like it is possible to have a resolution of 0.5 ms, but I failed to get this resolution.

Attached patch is much more simple than the previous one: it only changes _PyTime_gettimeofday().

----------
Added file: http://bugs.python.org/file24364/GetSystemTimeAsFileTime.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jan 31, 2012, 2:37 PM

Post #12 of 16 (52 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows [In reply to]

Changes by STINNER Victor <victor.stinner [at] haypocalc>:


Removed file: http://bugs.python.org/file24306/timespec-2.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Feb 7, 2012, 2:40 PM

Post #13 of 16 (42 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows [In reply to]

Roundup Robot <devnull [at] psf> added the comment:

New changeset bee7943d38c6 by Victor Stinner in branch 'default':
Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
http://hg.python.org/cpython/rev/bee7943d38c6

----------
nosy: +python-dev

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Feb 7, 2012, 2:41 PM

Post #14 of 16 (40 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows [In reply to]

Changes by STINNER Victor <victor.stinner [at] haypocalc>:


----------
resolution: -> fixed
status: open -> closed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Feb 8, 2012, 8:48 AM

Post #15 of 16 (38 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows [In reply to]

Éric Araujo <merwok [at] netwok> added the comment:

Please make sure to say “on Windows” in NEWS and commit messages when you’re doing platform-specific changes :)

----------
nosy: +eric.araujo

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Feb 8, 2012, 1:52 PM

Post #16 of 16 (40 views)
Permalink
[issue13845] Use GetSystemTimeAsFileTime() to get a resolution of 100 ns on Windows [In reply to]

Roundup Robot <devnull [at] psf> added the comment:

New changeset 3965ed809a85 by Victor Stinner in branch 'default':
Issue #13845: Fix NEWS entry, the change is specific to Windows
http://hg.python.org/cpython/rev/3965ed809a85

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.