perf: introduce a `--contains` flag to the `perfdirstate` command
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 08 Oct 2019 04:28:23 -0400
changeset 43197 0c4efb6eb4fa
parent 43196 5f9b1250b82a
child 43198 c16fe77e340a
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.
contrib/perf.py
tests/test-contrib-perf.t
--- a/contrib/perf.py	Tue Oct 08 04:23:04 2019 -0400
+++ b/contrib/perf.py	Tue Oct 08 04:28:23 2019 -0400
@@ -1101,10 +1101,24 @@
     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 @@
     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()
 
--- a/tests/test-contrib-perf.t	Tue Oct 08 04:23:04 2019 -0400
+++ b/tests/test-contrib-perf.t	Tue Oct 08 04:28:23 2019 -0400
@@ -205,6 +205,7 @@
   $ hg perfdirfoldmap
   $ hg perfdirs
   $ hg perfdirstate
+  $ hg perfdirstate --contains
   $ hg perfdirstate --iteration
   $ hg perfdirstatedirs
   $ hg perfdirstatefoldmap