[Python-Dev] PEP 418: Add monotonic clock

Steven D'Aprano steve at pearwood.info
Wed Mar 28 14:05:59 CEST 2012


Georg Brandl wrote:
> On 28.03.2012 06:45, Nick Coghlan wrote:
>> On Wed, Mar 28, 2012 at 10:36 AM, Victor Stinner
>> <victor.stinner at gmail.com> wrote:
>>> If QueryPerformanceCounter() is monotonic, the API can be simplified to:
>>>
>>>  * time.time() = system clock
>>>  * time.monotonic() = monotonic clock
>>>  * time.hires() = monotonic clock or fallback to system clock
>>>
>>> time.hires() definition is exactly what I was trying to implement with
>>> "time.steady(strict=True)" / "time.try_monotonic()".
>> Please don't call the fallback version "hires" as it suggests it may
>> be higher resolution than time.time() and that's completely the wrong
>> idea.
> 
> It's also a completely ugly name, since it's quite hard to figure out
> what it is supposed to stand for in the first place.

Precisely. I always read "hires" as the verb hires (as in "he hires a car to 
go on holiday") rather than HIgh RESolution.

-1 on hires, it's a horrible name. And misleading as well, because on Linux, 
it isn't any more high res than time.time().

+1 on Nick's suggestion of try_monotonic. It is clear and obvious and doesn't 
mislead.

I don't have an opinion as to what the implementation of try_monotonic should 
be. Whether it should fall back to time.time, time.clock, or something else, I 
don't know. But it is a clear and obvious solution for the use-case of "I 
prefer the monotonic clock, if it is available, otherwise I'll take my chances 
with a best-effect clock."



-- 
Steven



More information about the Python-Dev mailing list