# HG changeset patch # User Manuel Jacob # Date 1591314853 -7200 # Node ID c2df0bca0dfa30cdf177d37b852841002d670ee5 # Parent 2c920c4dbb31f376f7a29298e611370108d55ef2 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`. diff -r 2c920c4dbb31 -r c2df0bca0dfa contrib/perf.py --- a/contrib/perf.py Tue Jun 23 04:55:27 2020 +0200 +++ b/contrib/perf.py Fri Jun 05 01:54:13 2020 +0200 @@ -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 -r 2c920c4dbb31 -r c2df0bca0dfa relnotes/next --- a/relnotes/next Tue Jun 23 04:55:27 2020 +0200 +++ b/relnotes/next Fri Jun 05 01:54:13 2020 +0200 @@ -17,6 +17,10 @@ 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 == diff -r 2c920c4dbb31 -r c2df0bca0dfa tests/test-contrib-perf.t --- a/tests/test-contrib-perf.t Tue Jun 23 04:55:27 2020 +0200 +++ b/tests/test-contrib-perf.t Fri Jun 05 01:54:13 2020 +0200 @@ -180,7 +180,7 @@ perfvolatilesets benchmark the computation of various volatile set perfwalk (no help text available) - perfwrite microbenchmark ui.write + perfwrite microbenchmark ui.write (and others) (use 'hg help -v perf' to show built-in aliases and global options) $ hg perfaddremove