File: local_lifecycle.py

package info (click to toggle)
python-mitogen 0.3.39-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,732 kB
  • sloc: python: 24,733; sh: 198; makefile: 74; perl: 19; ansic: 18
file content (33 lines) | stat: -rw-r--r-- 887 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
Measure latency of .local() setup.
"""

import mitogen
import mitogen.core
import mitogen.utils
import ansible_mitogen.affinity


mitogen.utils.setup_gil()
#ansible_mitogen.affinity.policy.assign_worker()


@mitogen.main()
def main(router):
    import optparse
    parser = optparse.OptionParser(description=__doc__)
    parser.add_option(
        '-i', '--iterations', type=int, metavar='N', default=100,
        help='Number of iterations (default %default)')
    parser.add_option('--debug', action='store_true')
    opts, args = parser.parse_args()

    t0 = mitogen.core.now()
    for x in mitogen.core.range(opts.iterations):
        t = mitogen.core.now()
        f = router.local(debug=opts.debug)
        tt = mitogen.core.now()

    t1 = mitogen.core.now()
    mean = (t1 - t0) / opts.iterations
    print('++ iterations %d, mean %.03f ms' % (opts.iterations, 1e3 * mean))