[PATCH V2] perf: add historical portability for util.timer

Philippe Pepiot philippe.pepiot at logilab.fr
Thu Apr 6 08:55:28 EDT 2017


On 04/06/2017 02:31 PM, Yuya Nishihara wrote:
> On Wed, 05 Apr 2017 18:14:47 +0200, Philippe Pepiot wrote:
>> # HG changeset patch
>> # User Philippe Pepiot <philippe.pepiot at logilab.fr>
>> # Date 1491391351 -7200
>> #      Wed Apr 05 13:22:31 2017 +0200
>> # Node ID c0231296470330eeae91058b9a3d7a6785e16cbe
>> # Parent  04ec317b81280c189fcea33a05c8cbbac3c186b1
>> # Available At https://hg.logilab.org/users/ppepiot/hg
>> #              hg pull https://hg.logilab.org/users/ppepiot/hg -r c02312964703
>> perf: add historical portability for util.timer
>>
>> util.timer has been introduced in ae5d60bb and used in perf.py since 22fbca1d.
>> For historical portability, use locally defined timer.
>>
>> diff --git a/contrib/perf.py b/contrib/perf.py
>> --- a/contrib/perf.py
>> +++ b/contrib/perf.py
>> @@ -67,6 +67,14 @@ def safehasattr(thing, attr):
>>  setattr(util, 'safehasattr', safehasattr)
>>
>>  # for "historical portability":
>> +# use locally defined timer instead of util.timer, because util.timer has been
>> +# available since ae5d60bb70c9
>> +if safehasattr(time, 'perf_counter'):
>> +    timer = time.perf_counter
>> +else:
>> +    timer = time.time
>
> Any reason to drop time.clock() support?

I dropped windows support by mistake (previous version of perf.py was 
only using time.time).

>
> And I found "timer" is widely used in perf.py for different meaning. Perhaps
> we'll need another name. Sorry I didn't notice it yesterday.
>

Good catch, sorry to not have seen it before submission. I propose to 
forcibly define util.timer instead (like util.safehasattr).

Will send a V3


More information about the Mercurial-devel mailing list