| 1 |
""" |
| 2 |
Measure latency of .fork() setup/teardown. |
| 3 |
""" |
| 4 |
|
| 5 |
import mitogen |
| 6 |
import mitogen.core |
| 7 |
|
| 8 |
|
| 9 |
@mitogen.main() |
| 10 |
def main(router): |
| 11 |
import optparse |
| 12 |
parser = optparse.OptionParser(description=__doc__) |
| 13 |
parser.add_option( |
| 14 |
'-i', '--iterations', type=int, metavar='N', default=200, |
| 15 |
help='Number of iterations (default %default)') |
| 16 |
parser.add_option('--debug', action='store_true') |
| 17 |
opts, args = parser.parse_args() |
| 18 |
|
| 19 |
t0 = mitogen.core.now() |
| 20 |
for x in mitogen.core.range(opts.iterations): |
| 21 |
t = mitogen.core.now() |
| 22 |
ctx = router.fork(debug=opts.debug) |
| 23 |
ctx.shutdown(wait=True) |
| 24 |
|
| 25 |
t1 = mitogen.core.now() |
| 26 |
mean = (t1 - t0) / opts.iterations |
| 27 |
print('++ iterations %d, mean %.03f ms' % (opts.iterations, 1e3 * mean)) |