diff --git a/contrib/perf.py b/contrib/perf.py --- a/contrib/perf.py +++ b/contrib/perf.py @@ -3794,19 +3794,47 @@ def perflrucache( 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 @@ -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 --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 @@ -180,7 +180,7 @@ perfstatus 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