New submission from STINNER Victor <victor.stin...@gmail.com>:

The commit a997c7b434631f51e00191acea2ba6097691e859 of bpo-31415 moved the 
implementation of time.perf_counter() from Modules/timemodule.c to 
Python/pytime.c. The change not only moved the code, but also changed the 
internal type storing time from floatting point number (C double) to integer 
number (_PyTyime_t = int64_t).

The drawback of this change is that time.perf_counter() now converts 
QueryPerformanceCounter() / QueryPerformanceFrequency() double into a _PyTime_t 
(integer) and then back to double. Two useless conversions required by the 
_PyTime_t format used in Python/pytime.c. These conversions introduced a loss 
of precision.

Try attached round.py script which implements the double <=> _PyTime_t 
conversions and checks to check for precision loss. The script shows that we 
loose precision even with a single second for QueryPerformanceFrequency() == 
3579545.

It seems like QueryPerformanceFrequency() now returns 10 ** 7 (10_000_000, 
resolution of 100 ns) on Windows 8 and newer, but returns 3,579,545 (3.6 MHz, 
resolution of 279 ns) on Windows 7. It depends maybe on the hardware clock, I 
don't know. Anyway, whenever possible, we should avoid precision loss of a 
clock.

----------
components: Interpreter Core
files: round.py
messages: 304239
nosy: haypo
priority: normal
severity: normal
status: open
title: Rewrite _PyTime_GetWinPerfCounter() for _PyTime_t
type: enhancement
versions: Python 3.7
Added file: https://bugs.python.org/file47217/round.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31773>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to