[issue41303] perf_counter result does not count system sleep time in Mac OS
nooB
report at bugs.python.org
Thu Aug 6 09:50:58 EDT 2020
nooB <nsharish.mit at gmail.com> added the comment:
> perf_counter documentation says "It does include time elapsed during sleep and is system-wide." where "sleep" here means time.sleep()
Apologies for misinterpreting the documentation. A clock function that includes system suspend time can be useful. Consider this as a feature request.
I noticed that on both Linux and Mac OS, the functions time.monotonic and time.perf_counter are exactly same. They do not count time elapsed during suspend.
--- CODE -----
import time
for clock in "monotonic", "perf_counter":
print(f"{clock}: {time.get_clock_info(clock)}")
--- MAC OUTPUT ----
monotonic: namespace(adjustable=False, implementation='mach_absolute_time()', monotonic=True, resolution=1e-09)
perf_counter: namespace(adjustable=False, implementation='mach_absolute_time()', monotonic=True, resolution=1e-09)
--- LINUX OUTPUT --
monotonic: namespace(adjustable=False, implementation='clock_gettime(CLOCK_MONOTONIC)', monotonic=True, resolution=1e-09)
perf_counter: namespace(adjustable=False, implementation='clock_gettime(CLOCK_MONOTONIC)', monotonic=True, resolution=1e-09)
--------------
In Windows, perf_counter uses "QueryPerformanceCounter()" which includes "the time when the machine was in a sleep state such as standby, hibernate, or connected standby"
refer: https://docs.microsoft.com/en-us/windows/win32/sysinfo/acquiring-high-resolution-time-stamps
I learnt that "mach_continuous_time()" in Mac OS, "clock_gettime(CLOCK_BOOTTIME)" in Linux and "QueryPerformanceCounter()" in Windows all include system suspend time. It would be nice if perf_counter can be tweaked to provide similar behaviour across platforms. If it is not recommended, the mentioned functions can be exposed as a separate clock function.
Thanks.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41303>
_______________________________________
More information about the Python-bugs-list
mailing list