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

Yuya Nishihara yuya at tcha.org
Wed Apr 5 10:10:13 EDT 2017


On Wed, 05 Apr 2017 14:11:37 +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 8bec80c135fb155b8d10679900f08661b7f4d06a
> # Parent  04ec317b81280c189fcea33a05c8cbbac3c186b1
> # Available At https://hg.logilab.org/users/ppepiot/hg
> #              hg pull https://hg.logilab.org/users/ppepiot/hg -r 8bec80c135fb
> perf: add historical portability for util.timer
> 
> util.timer has been introduced in ae5d60bb and used in perf.py since 22fbca1d.
> For historical portability, define timer for early Mercurial.
> 
> diff --git a/contrib/perf.py b/contrib/perf.py
> --- a/contrib/perf.py
> +++ b/contrib/perf.py
> @@ -67,6 +67,16 @@ def safehasattr(thing, attr):
>  setattr(util, 'safehasattr', safehasattr)
>  
>  # for "historical portability":
> +# define timer locally because util.timer has been available since ae5d60bb70c9
> +if not safehasattr(util, 'timer'):
> +    if safehasattr(time, 'perf_counter'):
> +        timer = time.perf_counter
> +    else:
> +        timer = time.time
> +else:
> +    timer = util.timer

Maybe we always need to stick to the copy of util.timer? Otherwise, perf result
of old revision might use a different timer source and wouldn't be comparable
to the current result.


More information about the Mercurial-devel mailing list