tests: Parameterize and format output of large message benchmark

pull/1425/head
Alex Willmer 2 days ago
parent 2a172a3ad7
commit c9236b2360

@ -27,6 +27,7 @@ In progress (unreleased)
* :gh:issue:`1424` tests: Parameterize connection benchmarks
* :gh:issue:`1424` tests: Standardise output of connection benchmarks
* :gh:issue:`1424` tests: Parameterize throughput benchmark
* :gh:issue:`1424` tests: Parameterize large message benchmark
v0.3.37 (2026-01-08)

@ -1,4 +1,4 @@
# Verify _receive_one() quadratic behaviour fixed.
'Measure throughput of messages.'
import mitogen
import mitogen.core
@ -6,20 +6,27 @@ import mitogen.core
@mitogen.main()
def main(router):
c = router.fork()
import optparse
parser = optparse.OptionParser(description=__doc__)
parser.add_option(
'-i', '--iterations', type=int, metavar='N', default=10,
help='Number of iterations (default %default)')
parser.add_option('--debug', action='store_true')
opts, args = parser.parse_args()
c = router.fork(debug=opts.debug)
n = 1048576 * 127
s = ' ' * n
print('bytes in %.2fMiB string...' % (n/1048576.0),)
t0 = mitogen.core.now()
for x in range(10):
for x in range(opts.iterations):
tt0 = mitogen.core.now()
assert n == c.call(len, s)
print('took %dms' % (1000 * (mitogen.core.now() - tt0),))
t1 = mitogen.core.now()
print('total %dms / %dms avg / %.2fMiB/sec' % (
1000 * (t1 - t0),
(1000 * (t1 - t0)) / (x + 1),
((n * (x + 1)) / (t1 - t0)) / 1048576.0,
))
mean = (t1 - t0) / opts.iterations
transferred_size = n * opts.iterations
transfer_rate = transferred_size / (t1 - t0)
print('++ iterations %d, mean %.03f ms, rate %.03f MiB/s'
% (opts.iterations, 1e3 * mean, transfer_rate / 2**20))

Loading…
Cancel
Save