# HG changeset patch # User Pierre-Yves David # Date 2019-10-08 08:28:23 # Node ID 0c4efb6eb4fa84d2270cbef68b05f6d167858ff6 # Parent 5f9b1250b82a405cc29a0697529b64932c4a7023 perf: introduce a `--contains` flag to the `perfdirstate` command The new flag benchmark a large amount of `filepath in dirstate` call. This will be useful to compare the Python and Rust implementation of the dirstatemap. diff --git a/contrib/perf.py b/contrib/perf.py --- a/contrib/perf.py +++ b/contrib/perf.py @@ -1101,10 +1101,24 @@ def perfdirs(ui, repo, **opts): fm.end() -@command(b'perfdirstate', [ - (b'', b'iteration', None, - b'benchmark a full iteration for the dirstate'), - ] + formatteropts) +@command( + b'perfdirstate', + [ + ( + b'', + b'iteration', + None, + b'benchmark a full iteration for the dirstate', + ), + ( + b'', + b'contains', + None, + b'benchmark a large amount of `nf in dirstate` calls', + ), + ] + + formatteropts, +) def perfdirstate(ui, repo, **opts): """benchmap the time of various distate operations @@ -1116,13 +1130,31 @@ def perfdirstate(ui, repo, **opts): timer, fm = gettimer(ui, opts) b"a" in repo.dirstate + if opts[b'iteration'] and opts[b'contains']: + msg = b'only specify one of --iteration or --contains' + raise error.Abort(msg) + if opts[b'iteration']: setup = None dirstate = repo.dirstate + def d(): for f in dirstate: pass + + elif opts[b'contains']: + setup = None + dirstate = repo.dirstate + allfiles = list(dirstate) + # also add file path that will be "missing" from the dirstate + allfiles.extend([f[::-1] for f in allfiles]) + + def d(): + for f in allfiles: + f in dirstate + else: + def setup(): repo.dirstate.invalidate() diff --git a/tests/test-contrib-perf.t b/tests/test-contrib-perf.t --- a/tests/test-contrib-perf.t +++ b/tests/test-contrib-perf.t @@ -205,6 +205,7 @@ perfstatus $ hg perfdirfoldmap $ hg perfdirs $ hg perfdirstate + $ hg perfdirstate --contains $ hg perfdirstate --iteration $ hg perfdirstatedirs $ hg perfdirstatefoldmap