[PATCH 1 of 8 v4] mercurial: use best available timer for perf measurements

Martin von Zweigbergk martinvonz at google.com
Thu Feb 16 13:35:43 EST 2017


On Tue, Feb 14, 2017 at 8:51 AM, timeless <timeless at gmail.com> wrote:
> On Mon, Feb 13, 2017 at 12:29 PM, Simon Farnsworth <simonfar at fb.com> wrote:
>> mercurial: use best available timer for perf measurements
>>
>> As documented for timer.default_timer, there are better timers available for
>> performance measures on some platforms. These timers don't have a set epoch,
>> and thus are only useful for interval measurements, but have higher
>> resolution, and thus get you a better measurement overall.
>>
>> On newer Python (3.3 or later), there's time.perf_counter, which is
>
>> --- a/contrib/hgperf
>> +++ b/contrib/hgperf
>> -    begin = time.time()
>> +    begin = mercurial.util.timer()
>> --- a/mercurial/util.py
>> +++ b/mercurial/util.py
>> @@ -1203,8 +1203,13 @@
>>
>>  if pycompat.osname == 'nt':
>>      checkosfilename = checkwinfilename
>> +    timer = time.clock
>>  else:
>>      checkosfilename = platform.checkosfilename
>> +    timer = time.time
>> +
>> +if safehasattr(time, "perf_counter"):
>> +    timer = time.perf_counter

As discussed on #mercurial, Augie and I find "timer" confusing,
because it sounds like it returns a timer object, but in fact it just
returns a time. Can we have a followup patch that renames it to e.g.
perftime()?

>
> I think we usually split the introduction of a new feature from
> switching to using the new thing.
> It makes it easier to see / semi-document the new api vs. seeing the
> switch to using it.
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list