Created
November 8, 2010 23:29
-
-
Save ssadler/668473 to your computer and use it in GitHub Desktop.
code and results for different ways of doing recv() in pyzmq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os, os.path | |
sys.path.insert(0, os.getcwd()) | |
import zmq | |
addr = 'inproc://tmp1' | |
msg = '0' | |
copy = True | |
sw = zmq.Stopwatch() | |
cycles = int(sys.argv[1]) | |
c = zmq.Context() | |
s1 = c.socket(zmq.PUSH) | |
s1.bind(addr) | |
s2 = c.socket(zmq.PULL) | |
s2.connect(addr) | |
sw.start() | |
for i in xrange(cycles): | |
s1.send(msg, copy=copy) | |
assert msg == s2.recv(copy=copy) | |
usec = sw.stop() | |
print "zmq at:", os.path.dirname(zmq.__file__) | |
print "%.5f usecs per cycle" % (usec / float(cycles)) | |
""" | |
All tests performed with script as above: | |
# current HEAD of origin, always using message tracking (3bb1b19909125b1859042725895271b0a7e55818) | |
scott:~/dev/pyzmq_zeromq> python ../bench.py 1000000 | |
zmq at: /home/scott/dev/pyzmq_zeromq/zmq | |
52.90635 usecs per cycle | |
# Message(tracked=False) (ecc5e287a03f4579d5457b7151de31ffd20a72a6) | |
scott:~/dev/pyzmq> python ../bench.py 1000000 | |
zmq at: /home/scott/dev/pyzmq/zmq | |
4.52007 usecs per cycle | |
# Copy done directly in _recv_copy function (cc0545f811d7c41e5085c8d4a06a9276af99acd1) | |
scott:~/dev/pyzmq> python ../bench.py 1000000 | |
zmq at: /home/scott/dev/pyzmq/zmq | |
2.42329 usecs per cycle | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment