Mercurial > hg
comparison contrib/perf.py @ 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 | a0f2641ddd61 |
children | db6cace18765 |
comparison
equal
deleted
inserted
replaced
40924:08cfa77d7288 | 40925:008f3491dc53 |
---|---|
2610 if opts.get(b'dir') and not util.safehasattr(repo, b'dirlog'): | 2610 if opts.get(b'dir') and not util.safehasattr(repo, b'dirlog'): |
2611 raise error.Abort(b"This version doesn't support --dir option", | 2611 raise error.Abort(b"This version doesn't support --dir option", |
2612 hint=b"use 3.5 or later") | 2612 hint=b"use 3.5 or later") |
2613 return orig(repo, cmd, file_, opts) | 2613 return orig(repo, cmd, file_, opts) |
2614 extensions.wrapfunction(cmdutil, b'openrevlog', openrevlog) | 2614 extensions.wrapfunction(cmdutil, b'openrevlog', openrevlog) |
2615 | |
2616 @command(b'perfprogress', formatteropts + [ | |
2617 (b'', b'topic', b'topic', b'topic for progress messages'), | |
2618 (b'c', b'total', 1000000, b'total value we are progressing to'), | |
2619 ], norepo=True) | |
2620 def perfprogress(ui, topic=None, total=None, **opts): | |
2621 """printing of progress bars""" | |
2622 opts = _byteskwargs(opts) | |
2623 | |
2624 timer, fm = gettimer(ui, opts) | |
2625 | |
2626 def doprogress(): | |
2627 with ui.makeprogress(topic, total=total) as progress: | |
2628 for i in pycompat.xrange(total): | |
2629 progress.increment() | |
2630 | |
2631 timer(doprogress) | |
2632 fm.end() |