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.

Author kh90909
Recipients docs@python, kh90909, paul.moore, steve.dower, tim.golden, vstinner, zach.ware
Date 2019-06-08.18:14:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1560017700.11.0.127727162727.issue37205@roundup.psfhosted.org>
In-reply-to
Content
The documentation for time.perf_counter() indicates it should return a system-wide value: https://docs.python.org/3/library/time.html#time.perf_counter

This is not true on Windows, as a process-specific offset is subtracted from the underlying QueryPerformanceCounter() value. The code comments indicate this is to reduce precision loss: https://github.com/python/cpython/blob/master/Python/pytime.c#L995-L997

This is relevant in multiprocess applications, where accurate timing is required across multiple processes. Here is a simple test case:

-----------------------------------------------------------
import concurrent.futures
import time

def worker():
    return time.perf_counter()

if __name__ == '__main__':
    pool = concurrent.futures.ProcessPoolExecutor()
    futures = []
    for i in range(3):
        print('Submitting worker {:d} at time.perf_counter() == {:.3f}'.format(i, time.perf_counter()))
        futures.append(pool.submit(worker))
        time.sleep(1)

    for i, f in enumerate(futures):
        print('Worker {:d} started at time.perf_counter() == {:.3f}'.format(i, f.result()))
-----------------------------------------------------------

Output:
-----------------------------------------------------------
C:\...>Python37\python.exe -VV
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05)
[MSC v.1916 64 bit (AMD64)]

C:\...>Python37\python.exe perf_counter_across_processes.py
Submitting worker 0 at time.perf_counter() == 0.376
Submitting worker 1 at time.perf_counter() == 1.527
Submitting worker 2 at time.perf_counter() == 2.529
Worker 0 started at time.perf_counter() == 0.380
Worker 1 started at time.perf_counter() == 0.956
Worker 2 started at time.perf_counter() == 1.963
-----------------------------------------------------------

See my stackoverflow question for a comparison with Linux: https://stackoverflow.com/questions/56502111/should-time-perf-counter-be-consistent-across-processes-in-python-on-windows
History
Date User Action Args
2019-06-08 18:15:00kh90909setrecipients: + kh90909, paul.moore, vstinner, tim.golden, docs@python, zach.ware, steve.dower
2019-06-08 18:15:00kh90909setmessageid: <1560017700.11.0.127727162727.issue37205@roundup.psfhosted.org>
2019-06-08 18:15:00kh90909linkissue37205 messages
2019-06-08 18:14:59kh90909create