This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年01月24日 00:02 by vstinner, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| GetSystemTimeAsFileTime.patch | vstinner, 2012年01月30日 01:38 | review | ||
| Messages (12) | |||
|---|---|---|---|
| msg151865 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2012年01月24日 00:02 | |
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. |
|||
| msg151866 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2012年01月24日 00:11 | |
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(). |
|||
| msg151874 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2012年01月24日 01:27 | |
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). |
|||
| msg151892 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) | Date: 2012年01月24日 10:48 | |
GetSystemTimeAsFileTime() represent durations as multiple of 100ns, unfortunately its value is only updated every 15ms or so. Precision is not accuracy... |
|||
| msg151894 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2012年01月24日 11:22 | |
> 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. |
|||
| msg151897 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) | Date: 2012年01月24日 11:49 | |
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(). |
|||
| msg151901 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2012年01月24日 13:16 | |
> 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. |
|||
| msg152036 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2012年01月26日 21:51 | |
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! |
|||
| msg152298 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2012年01月30日 01:38 | |
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(). |
|||
| msg152817 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2012年02月07日 22:40 | |
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 |
|||
| msg152889 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2012年02月08日 16:48 | |
Please make sure to say "on Windows" in NEWS and commit messages when you’re doing platform-specific changes :) |
|||
| msg152911 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2012年02月08日 21:52 | |
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 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:26 | admin | set | github: 58053 |
| 2012年02月08日 21:52:46 | python-dev | set | messages: + msg152911 |
| 2012年02月08日 16:48:08 | eric.araujo | set | nosy:
+ eric.araujo messages: + msg152889 |
| 2012年02月07日 22:41:16 | vstinner | set | status: open -> closed resolution: fixed |
| 2012年02月07日 22:40:31 | python-dev | set | nosy:
+ python-dev messages: + msg152817 |
| 2012年01月31日 22:37:13 | vstinner | set | files: - timespec-2.patch |
| 2012年01月30日 01:38:39 | vstinner | set | files:
+ GetSystemTimeAsFileTime.patch messages: + msg152298 |
| 2012年01月26日 21:51:21 | vstinner | set | messages: + msg152036 |
| 2012年01月24日 13:16:59 | vstinner | set | messages: + msg151901 |
| 2012年01月24日 11:49:47 | amaury.forgeotdarc | set | messages: + msg151897 |
| 2012年01月24日 11:22:53 | vstinner | set | messages: + msg151894 |
| 2012年01月24日 10:48:56 | amaury.forgeotdarc | set | nosy:
+ amaury.forgeotdarc messages: + msg151892 |
| 2012年01月24日 04:11:51 | rosslagerwall | set | nosy:
+ rosslagerwall |
| 2012年01月24日 01:27:55 | vstinner | set | messages: + msg151874 |
| 2012年01月24日 00:11:42 | vstinner | set | files: - timespec.patch |
| 2012年01月24日 00:11:36 | vstinner | set | files:
+ timespec-2.patch messages: + msg151866 |
| 2012年01月24日 00:02:45 | vstinner | create | |