~ubuntu-branches/ubuntu/wily/pyzmq/wily

« back to all changes in this revision

Viewing changes to perf/local_lat.py

  • Committer: Package Import Robot
  • Author(s): Julian Taylor
  • Date: 2013-02-24 19:23:15 UTC
  • mfrom: (1.2.1) (9 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: package-import@ubuntu.com-20130224192315-qhmwp3m3ymk8r60d
Tags: 2.2.0.1-1
* New upstream release
* relicense debian packaging to LGPL-3
* update watch file to use github directly
  thanks to Bart Martens for the file
* add autopkgtests
* drop obsolete DM-Upload-Allowed
* bump standard to 3.9.4, no changes required

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import time
22
22
import zmq
23
23
 
24
 
def main():
25
 
    use_poll = '-p' in sys.argv
26
 
    use_copy = '-c' in sys.argv
 
24
 
 
25
def main(argv):
 
26
    use_poll = '-p' in argv
 
27
    use_copy = '-c' in argv
27
28
    if use_copy:
28
 
        sys.argv.remove('-c')
 
29
        argv.remove('-c')
29
30
    if use_poll:
30
 
        sys.argv.remove('-p')
 
31
        argv.remove('-p')
31
32
 
32
 
    if len (sys.argv) != 4:
33
 
        print 'usage: local_lat [-c use-copy] [-p use-poll] <bind-to> <message-size> <roundtrip-count>'
 
33
    if len (argv) != 4:
 
34
        print ('usage: local_lat [-c use-copy] [-p use-poll] <bind-to> <message-size> <roundtrip-count>')
34
35
        sys.exit (1)
35
36
 
36
37
    try:
37
 
        bind_to = sys.argv[1]
38
 
        message_size = int(sys.argv[2])
39
 
        roundtrip_count = int(sys.argv[3])
40
 
    except (ValueError, OverflowError), e:
41
 
        print 'message-size and roundtrip-count must be integers'
 
38
        bind_to = argv[1]
 
39
        message_size = int(argv[2])
 
40
        roundtrip_count = int(argv[3])
 
41
    except (ValueError, OverflowError):
 
42
        print ('message-size and roundtrip-count must be integers')
42
43
        sys.exit(1)
43
44
 
44
45
    ctx = zmq.Context()
49
50
        p.register(s)
50
51
 
51
52
    s.bind(bind_to)
52
 
 
 
53
    
 
54
    block = zmq.NOBLOCK if use_poll else 0
 
55
    
53
56
    for i in range(0, roundtrip_count):
54
57
        if use_poll:
55
58
            res = p.poll()
56
59
            assert(res[0][1] & zmq.POLLIN)
57
 
        msg = s.recv(zmq.NOBLOCK if use_poll else 0, copy=use_copy)
 
60
        msg = s.recv(block, copy=use_copy)
58
61
        assert len(msg) == message_size
59
62
 
60
63
        if use_poll:
61
64
            res = p.poll()
62
65
            assert(res[0][1] & zmq.POLLOUT)
63
 
        s.send(msg, zmq.NOBLOCK if use_poll else 0, copy=use_copy)
64
 
 
65
 
    # Let the context finish messaging before ending.
66
 
    # You may need to increase this time for longer or many messages.
67
 
    time.sleep(2.0)
 
66
        s.send(msg, block, copy=use_copy)
 
67
    
 
68
    msg = s.recv()
 
69
    # remove the b for Python2.5:
 
70
    assert msg == b'done'
 
71
    
 
72
    s.close()
 
73
    ctx.term()
68
74
 
69
75
if __name__ == '__main__':
70
 
    main()
 
76
    main(sys.argv)