Patchwork [1,of,2] perf: introduce a `--iteration` to `perfdirstate`

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 12, 2019, 2:20 a.m.
Message ID <992c09636ae9d0543ea6.1570846842@nodosa.octobus.net>
Download mbox | patch
Permalink /patch/42254/
State Accepted
Headers show

Comments

Pierre-Yves David - Oct. 12, 2019, 2:20 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1570522984 14400
#      Tue Oct 08 04:23:04 2019 -0400
# Node ID 992c09636ae9d0543ea621305a71d6f9f77dc7dc
# Parent  c88075eb28e3281a4470fde929fbf5a13bda5f8a
# EXP-Topic perf-dirstate
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 992c09636ae9
perf: introduce a `--iteration` to `perfdirstate`

This flag benchmark an iteration over all the file in the dirstate. This
will be useful to compare the Python and the Rust implementation of the
dirstate.
Yuya Nishihara - Oct. 13, 2019, 10:20 a.m.
On Sat, 12 Oct 2019 04:20:42 +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@octobus.net>
> # Date 1570522984 14400
> #      Tue Oct 08 04:23:04 2019 -0400
> # Node ID 992c09636ae9d0543ea621305a71d6f9f77dc7dc
> # Parent  c88075eb28e3281a4470fde929fbf5a13bda5f8a
> # EXP-Topic perf-dirstate
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 992c09636ae9
> perf: introduce a `--iteration` to `perfdirstate`

Fixed some missing b''s and queued, thanks.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -1101,10 +1101,14 @@  def perfdirs(ui, repo, **opts):
     fm.end()
 
 
-@command(b'perfdirstate', formatteropts)
+@command(b'perfdirstate', [
+            ('', 'iteration', None,
+             b'benchmark a full iteration for the dirstate'),
+        ] + formatteropts)
 def perfdirstate(ui, repo, **opts):
-    """benchmap the time necessary to load a dirstate from scratch
-
+    """benchmap the time of various distate operations
+
+    By default benchmark the time necessary to load a dirstate from scratch.
     The dirstate is loaded to the point were a "contains" request can be
     answered.
     """
@@ -1112,11 +1116,19 @@  def perfdirstate(ui, repo, **opts):
     timer, fm = gettimer(ui, opts)
     b"a" in repo.dirstate
 
-    def setup():
-        repo.dirstate.invalidate()
-
-    def d():
-        b"a" in repo.dirstate
+
+    if opts['iteration']:
+        setup = None
+        dirstate = repo.dirstate
+        def d():
+            for f in dirstate:
+                pass
+    else:
+        def setup():
+            repo.dirstate.invalidate()
+
+        def d():
+            b"a" in repo.dirstate
 
     timer(d, setup=setup)
     fm.end()
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
@@ -107,7 +107,7 @@  perfstatus
    perfdirfoldmap
                  benchmap a 'dirstate._map.dirfoldmap.get()' request
    perfdirs      (no help text available)
-   perfdirstate  benchmap the time necessary to load a dirstate from scratch
+   perfdirstate  benchmap the time of various distate operations
    perfdirstatedirs
                  benchmap a 'dirstate.hasdir' call from an empty 'dirs' cache
    perfdirstatefoldmap
@@ -205,6 +205,7 @@  perfstatus
   $ hg perfdirfoldmap
   $ hg perfdirs
   $ hg perfdirstate
+  $ hg perfdirstate --iteration
   $ hg perfdirstatedirs
   $ hg perfdirstatefoldmap
   $ hg perfdirstatewrite