-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
precise time.time() under Windows 8: use GetSystemTimePreciseAsFileTime #63207
Comments
For whoever is interested: Windows 8 apparently has a new API named GetSystemTimePreciseAsFileTime which returns the system API with a much better resolution than GetSystemTimeAsFileTime does ("The GetSystemTimePreciseAsFileTime function retrieves the current system date and time with the highest possible level of precision (<1us)"). (spawned from this topic on the tulip mailing-list: https://groups.google.com/forum/#!topic/python-tulip/vX9vOZB1FOI ) |
time.time() is sometimes used in performance critical code. Is GetSystemTimePreciseAsFileTime() as fast as GetSystemTimeAsFileTime()? Linux has the opposite: CLOCK_REALTIME_COARSE. This clock is less accurate but may be faster. |
"GetSystemTimePreciseAsFileTime() has very little overhead; the new function is even a little faster than GetSystemTimeAsFileTime(), a call takes a few ten nanoseconds." |
My patch for the issue bpo-22043 replaces the _PyTime_timeval structure (10^-6 second resolution, 1 us) with a _PyTime_timespec structure (10^-9 second resolution, 1 ns). It may help for this issue. |
Python 3.5 has a new C function _PyTime_GetSystemClock() which uses the new _PyTime_t type. It now has a resolution of 1 nanosecond. Sorry, I don't have Windows 8 at home, so I cannot work on this issue. I guess that we should check at runtime if GetSystemTimePreciseAsFileTime() is available, as we did for GetTickCount64() in the past: hKernel32 = GetModuleHandleW(L"KERNEL32");
*(FARPROC*)&Py_GetTickCount64 = GetProcAddress(hKernel32,
"GetTickCount64"); Is there any Windows developer interested to write a short patch to implement it? |
Good news! I got a new fresh Windows 8.1 VM with Visual Studio 2015. I'm now able to work on this issue. I wrote a patch: time_precise.patch. Resolution computed in Python by https://hg.python.org/peps/file/tip/pep-0418/clock_resolution.py: GetSystemTimePreciseAsFileTime(): 715 ns Obviously, the resolution is better... GetSystemTimePreciseAsFileTime() uses internally the QueryPerformanceCounter() so I chose to use QueryPerformanceFrequency() to fill time.get_clock_info('time').resolution, same code than time.get_clock_info('perf_counter').resolution |
Note: GetSystemTimePreciseAsFileTime() is restricted to desktop applications. The windowstimestamp.com has a warning on this function: http://www.windowstimestamp.com/description """ (...) Is it ok to switch to GetSystemTimePreciseAsFileTime() for Python time.time()? |
What are the expected benefits from changing? Just a higher resolution? I'm not sure that's worth anything if it's inaccurate. |
The system uses a similar procedure in
The above claim was corrected back in 2014. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: