Mercurial > hg
changeset 40925:008f3491dc53
perf: add perfprogress command
I've noticed that progress bars can add significant overhead to tight
loops. Let's add a perf command that attempts to isolate that overhead.
With a default hgrc, iteration over 1M items appears to take ~3.75s on
my machine. Profiling reveals ~28% of time is spent in ui.configbool()
resolving the value of the progress.debug config option.
Even if I set progress.disable=true, execution still takes ~2.60s, with
~59% of the time spent in ui.configbool().
Differential Revision: https://phab.mercurial-scm.org/D5407
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 10 Dec 2018 20:01:07 +0000 |
parents | 08cfa77d7288 |
children | c9c10430fd7f |
files | contrib/perf.py tests/test-contrib-perf.t |
diffstat | 2 files changed, 20 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/perf.py Mon Dec 10 18:55:08 2018 +0000 +++ b/contrib/perf.py Mon Dec 10 20:01:07 2018 +0000 @@ -2612,3 +2612,21 @@ hint=b"use 3.5 or later") return orig(repo, cmd, file_, opts) extensions.wrapfunction(cmdutil, b'openrevlog', openrevlog) + +@command(b'perfprogress', formatteropts + [ + (b'', b'topic', b'topic', b'topic for progress messages'), + (b'c', b'total', 1000000, b'total value we are progressing to'), +], norepo=True) +def perfprogress(ui, topic=None, total=None, **opts): + """printing of progress bars""" + opts = _byteskwargs(opts) + + timer, fm = gettimer(ui, opts) + + def doprogress(): + with ui.makeprogress(topic, total=total) as progress: + for i in pycompat.xrange(total): + progress.increment() + + timer(doprogress) + fm.end()
--- a/tests/test-contrib-perf.t Mon Dec 10 18:55:08 2018 +0000 +++ b/tests/test-contrib-perf.t Mon Dec 10 20:01:07 2018 +0000 @@ -112,6 +112,7 @@ perfphases benchmark phasesets computation perfphasesremote benchmark time needed to analyse phases of the remote server + perfprogress printing of progress bars perfrawfiles (no help text available) perfrevlogchunks Benchmark operations on revlog chunks. @@ -188,6 +189,7 @@ $ hg perfmoonwalk $ hg perfnodelookup 2 $ hg perfpathcopies 1 2 + $ hg perfprogress --total 1000 $ hg perfrawfiles 2 $ hg perfrevlogindex -c #if reporevlogstore