Patchwork [v2] perf: make `hg perfwrite` more flexible

login
register
mail settings
Submitter Manuel Jacob
Date June 23, 2020, 1:37 a.m.
Message ID <d0bfd96406c0212f1467.1592876271@tmp>
Download mbox | patch
Permalink /patch/46546/
State Accepted
Headers show

Comments

Manuel Jacob - June 23, 2020, 1:37 a.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1591314853 -7200
#      Fri Jun 05 01:54:13 2020 +0200
# Node ID d0bfd96406c0212f146728080dfdd002118960f9
# Parent  61719b9658b156548634c216ffb2b9188266293b
# EXP-Topic perfwrite2
perf: make `hg perfwrite` more flexible

The more flexible command was used recently while finding a solution for a
buffering bug (eventually fixed in f9734b2d59cc (the changeset description uses
a different benchmark)).

In comparison to the previous version, the new version is much more flexible.
While using it, the focus was on testing small writes. For this reason, by
default it calls ui.write() 100 times with a single byte plus one newline byte,
for 100 lines.

To get the previous behavior, run `hg perfwrite --nlines=100000 --nitems=1
--item='Testing write performance' --batch-line`.
Yuya Nishihara - June 23, 2020, 12:06 p.m.
On Tue, 23 Jun 2020 03:37:51 +0200, Manuel Jacob wrote:
> # HG changeset patch
> # User Manuel Jacob <me@manueljacob.de>
> # Date 1591314853 -7200
> #      Fri Jun 05 01:54:13 2020 +0200
> # Node ID d0bfd96406c0212f146728080dfdd002118960f9
> # Parent  61719b9658b156548634c216ffb2b9188266293b
> # EXP-Topic perfwrite2
> perf: make `hg perfwrite` more flexible

Queued, thanks.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -3794,19 +3794,47 @@ 
         fm.end()
 
 
-@command(b'perfwrite', formatteropts)
+@command(
+    b'perfwrite',
+    formatteropts
+    + [
+        (b'', b'write-method', b'write', b'ui write method'),
+        (b'', b'nlines', 100, b'number of lines'),
+        (b'', b'nitems', 100, b'number of items (per line)'),
+        (b'', b'item', b'x', b'item that is written'),
+        (b'', b'batch-line', None, b'pass whole line to write method at once'),
+        (b'', b'flush-line', None, b'flush after each line'),
+    ],
+)
 def perfwrite(ui, repo, **opts):
-    """microbenchmark ui.write
+    """microbenchmark ui.write (and others)
     """
     opts = _byteskwargs(opts)
 
+    write = getattr(ui, _sysstr(opts[b'write_method']))
+    nlines = int(opts[b'nlines'])
+    nitems = int(opts[b'nitems'])
+    item = opts[b'item']
+    batch_line = opts.get(b'batch_line')
+    flush_line = opts.get(b'flush_line')
+
+    if batch_line:
+        line = item * nitems + b'\n'
+
+    def benchmark():
+        for i in pycompat.xrange(nlines):
+            if batch_line:
+                write(line)
+            else:
+                for i in pycompat.xrange(nitems):
+                    write(item)
+                write(b'\n')
+            if flush_line:
+                ui.flush()
+        ui.flush()
+
     timer, fm = gettimer(ui, opts)
-
-    def write():
-        for i in range(100000):
-            ui.writenoi18n(b'Testing write performance\n')
-
-    timer(write)
+    timer(benchmark)
     fm.end()
 
 
diff --git a/relnotes/next b/relnotes/next
--- a/relnotes/next
+++ b/relnotes/next
@@ -16,6 +16,9 @@ 
   backported modern SSL/TLS features (as defined in PEP 466), and that Python
   was compiled against a OpenSSL version supporting TLS 1.1 or TLS 1.2
   (likely this requires the OpenSSL version to be at least 1.0.1).
+* The `hg perfwrite` command from contrib/perf.py was made more flexible and
+  changed its default behavior. To get the previous behavior, run `hg perfwrite
+  --nlines=100000 --nitems=1 --item='Testing write performance' --batch-line`.
 
 
 == Internal API Changes ==