[issue19007] precise time.time() under Windows 8: use GetSystemTimePreciseAsFileTime

2021-06-13 Thread Eryk Sun


Eryk Sun  added the comment:

> What are the expected benefits from changing? Just a higher 
> resolution? I'm not sure that's worth anything if it's inaccurate.

GetSystemTimePreciseAsFileTime() returns an accurate timestamp, which is the 
current system time plus the difference between the current value of the 
performance counter and its value when the system time was last updated. This 
can't be replicated simply with separate calls to GetSystemTimeAsFileTime() and 
QueryPerformanceCounter(). It relies on the following undocumented fields in 
the KUSER_SHARED_DATA record: BaselineSystemTimeQpc, QpcSystemTimeIncrement, 
and QpcSystemTimeIncrementShift. 

The system uses a similar procedure in QueryInterruptTimePrecise() to extend 
the precision of QueryInterruptTime(). Ditto for QueryUnbiasedInterruptTime() 
vs QueryUnbiasedInterruptTimePrecise().

> "GetSystemTimePreciseAsFileTime() has very little overhead; the new 
> function is even a little faster than GetSystemTimeAsFileTime(), a 
> call takes a few ten nanoseconds."

The above claim was corrected back in 2014. GetSystemTimePreciseAsFileTime() is 
considerably more expensive than GetSystemTimeAsFileTime(). It costs about 10 
times more on a system that supports an invariant TSC. It would be more 
expensive on an older system that use the chipset's HPET or ACPI PM timer. That 
said, I doubt this matters very much when calling time.time() in interpreted 
code. It's a difference measured in tens of nanoseconds.

--
nosy: +eryksun
versions: +Python 3.11 -Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19007] precise time.time() under Windows 8: use GetSystemTimePreciseAsFileTime

2015-08-01 Thread Steve Dower

Steve Dower added the comment:

What are the expected benefits from changing? Just a higher resolution? I'm not 
sure that's worth anything if it's inaccurate.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19007
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19007] precise time.time() under Windows 8: use GetSystemTimePreciseAsFileTime

2015-07-31 Thread STINNER Victor

STINNER Victor added the comment:

Note: GetSystemTimePreciseAsFileTime() is restricted to desktop applications.

The windowstimestamp.com has a warning on this function:

http://www.windowstimestamp.com/description


2.1.4.2.  Desktop Applications: GetSystemTimePreciseAsFileTime()

(...)
The function shall also be used with care when a system time adjustment is 
active. Current Windows versions treat the performance counter frequency as a 
constant. The high resolution of GetSystemTimePreciseAsFileTime() is derived 
from the performance counter value at the time of the call and the performance 
counter frequency. However, the performance counter frequency should be 
corrected during system time adjustments to adapt to the modified progress in 
time. Current Windows versions don't do this. The obtained microsecond part may 
be severely affected when system time adjustments are active. Seconds may 
consist of more or less than 1.000.000 microseconds. Microsoft may or not fix 
this in one of the next updates/versions.
(...)
As of May, 2015 the inaccuracy of GetSystemTimePreciseAsFileTime() during 
system time adjustments persists for the preview versions of Windows 10.


Is it ok to switch to GetSystemTimePreciseAsFileTime() for Python time.time()?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19007
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19007] precise time.time() under Windows 8: use GetSystemTimePreciseAsFileTime

2015-07-31 Thread STINNER Victor

STINNER Victor added the comment:

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
GetSystemTimeAsFileTime(): 14 ms

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

--
keywords: +patch
Added file: http://bugs.python.org/file40088/time_precise.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19007
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19007] precise time.time() under Windows 8: use GetSystemTimePreciseAsFileTime

2015-07-21 Thread STINNER Victor

STINNER Victor added the comment:

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(LKERNEL32);
*(FARPROC*)Py_GetTickCount64 = GetProcAddress(hKernel32,
   GetTickCount64);

Is there any Windows developer interested to write a short patch to implement 
it?

--
versions: +Python 3.6 -Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19007
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19007] precise time.time() under Windows 8: use GetSystemTimePreciseAsFileTime

2015-07-20 Thread Akira Li

Changes by Akira Li 4kir4...@gmail.com:


--
nosy: +akira

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19007
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19007] precise time.time() under Windows 8

2014-07-30 Thread Mark Lawrence

Changes by Mark Lawrence breamore...@yahoo.co.uk:


--
nosy: +steve.dower, tim.golden, zach.ware
versions: +Python 3.5 -Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19007
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19007] precise time.time() under Windows 8

2014-07-30 Thread STINNER Victor

STINNER Victor added the comment:

My patch for the issue #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 tracker rep...@bugs.python.org
http://bugs.python.org/issue19007
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19007] precise time.time() under Windows 8: use GetSystemTimePreciseAsFileTime

2014-07-30 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@gmail.com:


--
title: precise time.time() under Windows 8 - precise time.time() under Windows 
8: use GetSystemTimePreciseAsFileTime

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19007
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19007] precise time.time() under Windows 8

2013-09-12 Thread STINNER Victor

STINNER Victor added the comment:

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.
http://lwn.net/Articles/342018/

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19007
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19007] precise time.time() under Windows 8

2013-09-12 Thread Antoine Pitrou

Antoine Pitrou added the comment:

GetSystemTimePreciseAsFileTime() has very little overhead; the new function is 
even a little faster than GetSystemTimeAsFileTime(), a call takes a few ten 
nanoseconds.

from http://www.windowstimestamp.com/description#C_2

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19007
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19007] precise time.time() under Windows 8

2013-09-12 Thread Antoine Pitrou

New submission from Antoine Pitrou:

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)).
http://msdn.microsoft.com/en-us/library/windows/desktop/hh706895%28v=vs.85%29.aspx

(spawned from this topic on the tulip mailing-list: 
https://groups.google.com/forum/#!topic/python-tulip/vX9vOZB1FOI )

--
components: Library (Lib), Windows
messages: 197538
nosy: belopolsky, haypo, lemburg, pitrou, tim.peters
priority: low
severity: normal
status: open
title: precise time.time() under Windows 8
type: enhancement
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19007
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com