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.

classification
Title: perf_counter() returns computers uptime
Type: behavior Stage: resolved
Components: Versions: Python 3.10
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Dennis Sweeney, eryksun, terry.reedy, txhx38
Priority: normal Keywords:

Created on 2021-03-21 16:38 by txhx38, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg389248 - (view) Author: Tobi (txhx38) Date: 2021-03-21 16:38
perf_counter() does not behave as expected
msg389249 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2021-03-21 16:55
Can you explain why you think this is the wrong behavior, and what operating system and version of Python you're using?


from https://docs.python.org/3/library/time.html#time.perf_counter

Return the value (in fractional seconds) of a performance counter, i.e. a clock with the highest available resolution to measure a short duration. It does include time elapsed during sleep and is system-wide. The reference point of the returned value is undefined, so that only the difference between the results of two calls is valid.


Returning the uptime seems like acceptable behavior to me, since "the reference point ... is undefined".
msg389262 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-03-21 22:01
For Windows, starting with Python 3.10, the value of time.perf_counter[_ns]() is system wide instead of relative to the first time it's accessed in the current process. This allows comparing the counter value across processes. See bpo-37205.
msg389561 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-03-26 19:17
Eryk, if I understand correctly, this should be closed as 'not a bug'.  Correct?
msg389563 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-03-26 19:36
I think so. But I'll mark it pending for now in case Tobi provides more information to explain why this is a problem. Making time.perf_counter() system-wide in Windows was fixing it to match the documented behavior. That this provides the system uptime is a natural consequence of how the system performance counter is implemented consistently for all processes for the entire uptime of the system.
History
Date User Action Args
2022-04-11 14:59:43adminsetgithub: 87751
2021-08-09 03:31:39Dennis Sweeneysetstatus: pending -> closed
resolution: not a bug
stage: resolved
2021-03-26 19:36:05eryksunsetstatus: open -> pending
type: behavior
messages: + msg389563
2021-03-26 19:17:28terry.reedysetnosy: + terry.reedy
messages: + msg389561
2021-03-21 22:01:27eryksunsetnosy: + eryksun
messages: + msg389262
2021-03-21 16:55:27Dennis Sweeneysetnosy: + Dennis Sweeney
messages: + msg389249
2021-03-21 16:38:13txhx38create