Skip to content

Instantly share code, notes, and snippets.

@ssadler
Created November 6, 2010 04:30
Show Gist options
  • Save ssadler/665195 to your computer and use it in GitHub Desktop.
Save ssadler/665195 to your computer and use it in GitHub Desktop.
server.py
> python -m cProfile -s time client.py
3806027 function calls (3805761 primitive calls) in 39.336 CPU seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
100000 21.909 0.000 37.780 0.000 {method 'recv_multipart' of 'zmq._zmq.Socket' objects}
900002 8.073 0.000 8.920 0.000 threading.py:179(__init__)
900002 3.256 0.000 12.176 0.000 threading.py:174(Condition)
300000 3.061 0.000 15.871 0.000 Queue.py:22(__init__)
100000 1.169 0.000 1.169 0.000 {method 'send_multipart' of 'zmq._zmq.Socket' objects}
900004 0.847 0.000 0.847 0.000 threading.py:59(__init__)
300000 0.377 0.000 0.377 0.000 Queue.py:197(_init)
1 0.366 0.366 39.336 39.336 client.py:1(<module>)
300003 0.256 0.000 0.256 0.000 {thread.allocate_lock}
380 0.004 0.000 0.004 0.000 sre_parse.py:136(__getitem__)
1 0.004 0.004 0.020 0.020 __init__.py:1(<module>)
101/14 0.003 0.000 0.008 0.001 sre_compile.py:38(_compile)
56/22 0.001 0.000 0.004 0.000 sre_parse.py:385(_parse)
362 0.001 0.000 0.001 0.000 sre_parse.py:188(__next)
26 0.001 0.000 0.001 0.000 sre_compile.py:213(_optimize_charset)
127/40 0.001 0.000 0.001 0.000 sre_parse.py:146(getwidth)
1281/1241 0.001 0.000 0.001 0.000 {len}
1217 0.001 0.000 0.001 0.000 {method 'append' of 'list' objects}
1 0.000 0.000 0.001 0.001 threading.py:1(<module>)
1 0.000 0.000 0.000 0.000 heapq.py:31(<module>)
291 0.000 0.000 0.001 0.000 sre_parse.py:207(get)
1 0.000 0.000 0.013 0.013 decoder.py:2(<module>)
1 0.000 0.000 0.001 0.001 Queue.py:1(<module>)
1 0.000 0.000 0.000 0.000 random.py:40(<module>)
424 0.000 0.000 0.000 0.000 {isinstance}
40/22 0.000 0.000 0.004 0.000 sre_parse.py:307(_parse_sub)
1 0.000 0.000 0.015 0.015 __init__.py:98(<module>)
14 0.000 0.000 0.001 0.000 sre_compile.py:367(_compile_info)
3 0.000 0.000 0.000 0.000 sre_compile.py:264(_mk_bitmap)
1 0.000 0.000 0.000 0.000 collections.py:1(<module>)
165 0.000 0.000 0.000 0.000 sre_parse.py:144(append)
1 0.000 0.000 39.336 39.336 {execfile}
235 0.000 0.000 0.000 0.000 {min}
26 0.000 0.000 0.001 0.000 sre_compile.py:184(_compile_charset)
192 0.000 0.000 0.000 0.000 sre_parse.py:201(match)
140 0.000 0.000 0.000 0.000 sre_parse.py:132(__len__)
22 0.000 0.000 0.005 0.000 sre_parse.py:669(parse)
1 0.000 0.000 0.001 0.001 encoder.py:2(<module>)
1 0.000 0.000 0.000 0.000 {method 'connect' of 'zmq._zmq.Socket' objects}
1 0.000 0.000 0.000 0.000 threading.py:57(_Verbose)
12 0.000 0.000 0.006 0.001 re.py:229(_compile)
101 0.000 0.000 0.000 0.000 sre_parse.py:96(__init__)
14 0.000 0.000 0.012 0.001 sre_compile.py:501(compile)
1 0.000 0.000 0.000 0.000 scanner.py:3(<module>)
26 0.000 0.000 0.000 0.000 sre_compile.py:360(_simple)
137 0.000 0.000 0.000 0.000 {ord}
2 0.000 0.000 0.008 0.004 scanner.py:18(__init__)
15 0.000 0.000 0.000 0.000 sre_parse.py:231(_class_escape)
14 0.000 0.000 0.010 0.001 sre_compile.py:486(_code)
1 0.000 0.000 0.000 0.000 bisect.py:1(<module>)
22 0.000 0.000 0.000 0.000 sre_parse.py:184(__init__)
32 0.000 0.000 0.000 0.000 {method 'format' of 'str' objects}
56 0.000 0.000 0.000 0.000 {method 'get' of 'dict' objects}
26 0.000 0.000 0.000 0.000 sre_compile.py:480(isstring)
16 0.000 0.000 0.000 0.000 sre_parse.py:263(_escape)
74 0.000 0.000 0.000 0.000 sre_compile.py:24(_identityfunction)
14 0.000 0.000 0.000 0.000 {_sre.compile}
33 0.000 0.000 0.000 0.000 {max}
15 0.000 0.000 0.000 0.000 sre_parse.py:78(opengroup)
24 0.000 0.000 0.000 0.000 sre_parse.py:73(__init__)
32 0.000 0.000 0.000 0.000 {method 'setdefault' of 'dict' objects}
1 0.000 0.000 0.000 0.000 {method 'socket' of 'zmq._zmq.Context' objects}
15 0.000 0.000 0.000 0.000 sre_parse.py:89(closegroup)
32 0.000 0.000 0.000 0.000 {chr}
1 0.000 0.000 0.000 0.000 __future__.py:48(<module>)
26 0.000 0.000 0.000 0.000 sre_parse.py:140(__setitem__)
1 0.000 0.000 0.002 0.002 decoder.py:244(JSONDecoder)
10 0.000 0.000 0.000 0.000 {range}
1 0.000 0.000 0.000 0.000 warnings.py:45(filterwarnings)
12 0.000 0.000 0.006 0.001 re.py:188(compile)
1 0.000 0.000 0.000 0.000 threading.py:412(Thread)
1 0.000 0.000 0.000 0.000 {function seed at 0xb7618f7c}
1 0.000 0.000 0.000 0.000 traceback.py:1(<module>)
1 0.000 0.000 0.000 0.000 random.py:99(seed)
1 0.000 0.000 0.000 0.000 {math.exp}
1 0.000 0.000 0.000 0.000 threading.py:424(__init__)
5 0.000 0.000 0.004 0.001 scanner.py:65(decorator)
1 0.000 0.000 0.000 0.000 keyword.py:11(<module>)
1 0.000 0.000 0.000 0.000 {posix.open}
1 0.000 0.000 0.000 0.000 random.py:71(Random)
15 0.000 0.000 0.000 0.000 {method 'remove' of 'list' objects}
14 0.000 0.000 0.000 0.000 {method 'items' of 'dict' objects}
1 0.000 0.000 0.000 0.000 threading.py:737(__init__)
1 0.000 0.000 0.000 0.000 os.py:747(urandom)
12 0.000 0.000 0.000 0.000 {_sre.getlower}
1 0.000 0.000 0.000 0.000 {posix.read}
1 0.000 0.000 0.000 0.000 threading.py:364(__init__)
11 0.000 0.000 0.000 0.000 {method 'extend' of 'list' objects}
2 0.000 0.000 0.000 0.000 {math.log}
1 0.000 0.000 0.000 0.000 threading.py:374(set)
5 0.000 0.000 0.000 0.000 scanner.py:64(pattern)
1 0.000 0.000 0.000 0.000 encoder.py:87(JSONEncoder)
1 0.000 0.000 0.000 0.000 threading.py:270(notify)
7 0.000 0.000 0.000 0.000 __future__.py:75(__init__)
1 0.000 0.000 0.000 0.000 Queue.py:17(Queue)
1 0.000 0.000 0.000 0.000 threading.py:288(notifyAll)
3 0.000 0.000 0.000 0.000 {built-in method acquire}
1 0.000 0.000 0.000 0.000 threading.py:99(_RLock)
1 0.000 0.000 0.000 0.000 threading.py:177(_Condition)
3 0.000 0.000 0.000 0.000 sre_parse.py:213(seek)
2 0.000 0.000 0.000 0.000 {method 'setter' of 'property' objects}
1 0.000 0.000 0.000 0.000 encoder.py:119(__init__)
1 0.000 0.000 0.000 0.000 threading.py:357(Event)
1 0.000 0.000 0.000 0.000 {math.sqrt}
1 0.000 0.000 39.336 39.336 <string>:1(<module>)
1 0.000 0.000 0.000 0.000 {binascii.hexlify}
1 0.000 0.000 0.000 0.000 random.py:643(WichmannHill)
1 0.000 0.000 0.000 0.000 {posix.close}
1 0.000 0.000 0.000 0.000 random.py:793(SystemRandom)
1 0.000 0.000 0.000 0.000 decoder.py:276(__init__)
2 0.000 0.000 0.000 0.000 {built-in method release}
1 0.000 0.000 0.000 0.000 random.py:90(__init__)
1 0.000 0.000 0.000 0.000 threading.py:219(_is_owned)
1 0.000 0.000 0.000 0.000 Queue.py:212(PriorityQueue)
1 0.000 0.000 0.000 0.000 threading.py:360(_Event)
1 0.000 0.000 0.000 0.000 __future__.py:74(_Feature)
1 0.000 0.000 0.000 0.000 scanner.py:17(Scanner)
1 0.000 0.000 0.000 0.000 threading.py:735(_MainThread)
1 0.000 0.000 0.000 0.000 threading.py:345(_BoundedSemaphore)
3 0.000 0.000 0.000 0.000 sre_parse.py:211(tell)
1 0.000 0.000 0.000 0.000 threading.py:297(_Semaphore)
1 0.000 0.000 0.000 0.000 threading.py:503(_set_ident)
1 0.000 0.000 0.000 0.000 threading.py:706(_Timer)
2 0.000 0.000 0.000 0.000 {thread.get_ident}
1 0.000 0.000 0.000 0.000 threading.py:745(_set_daemon)
1 0.000 0.000 0.000 0.000 threading.py:776(_DummyThread)
1 0.000 0.000 0.000 0.000 Queue.py:13(Full)
1 0.000 0.000 0.000 0.000 {method 'insert' of 'list' objects}
1 0.000 0.000 0.000 0.000 Queue.py:9(Empty)
1 0.000 0.000 0.000 0.000 Queue.py:231(LifoQueue)
1 0.000 0.000 0.000 0.000 {issubclass}
1 0.000 0.000 0.000 0.000 threading.py:64(_note)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
import sys, zmq
c = zmq.Context()
s = c.socket(zmq.XREQ)
s.connect('tcp://127.0.0.1:12000')
tosend = ['addr', '', '0123456789']
for i in xrange(100000):
s.send_multipart(tosend, copy=True)
out = s.recv_multipart()
> python -m cProfile -s time server.py
1506028 function calls (1505762 primitive calls) in 40.276 CPU seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
100000 33.404 0.000 38.771 0.000 {method 'recv_multipart' of 'zmq._zmq.Socket' objects}
300002 2.727 0.000 3.012 0.000 threading.py:179(__init__)
300002 1.075 0.000 4.087 0.000 threading.py:174(Condition)
100000 1.061 0.000 5.367 0.000 Queue.py:22(__init__)
100000 0.823 0.000 0.823 0.000 {method 'send_multipart' of 'zmq._zmq.Socket' objects}
1 0.505 0.505 40.276 40.276 server.py:1(<module>)
300004 0.284 0.000 0.284 0.000 threading.py:59(__init__)
100000 0.160 0.000 0.160 0.000 server.py:5(<lambda>)
100000 0.126 0.000 0.126 0.000 Queue.py:197(_init)
100003 0.091 0.000 0.091 0.000 {thread.allocate_lock}
1 0.004 0.004 0.017 0.017 __init__.py:1(<module>)
235 0.002 0.000 0.002 0.000 {min}
101/14 0.001 0.000 0.003 0.000 sre_compile.py:38(_compile)
56/22 0.001 0.000 0.004 0.000 sre_parse.py:385(_parse)
362 0.001 0.000 0.001 0.000 sre_parse.py:188(__next)
127/40 0.001 0.000 0.002 0.000 sre_parse.py:146(getwidth)
26 0.001 0.000 0.001 0.000 sre_compile.py:213(_optimize_charset)
1281/1241 0.001 0.000 0.001 0.000 {len}
1217 0.001 0.000 0.001 0.000 {method 'append' of 'list' objects}
380 0.001 0.000 0.001 0.000 sre_parse.py:136(__getitem__)
1 0.000 0.000 0.001 0.001 threading.py:1(<module>)
1 0.000 0.000 0.000 0.000 heapq.py:31(<module>)
291 0.000 0.000 0.001 0.000 sre_parse.py:207(get)
1 0.000 0.000 0.001 0.001 Queue.py:1(<module>)
1 0.000 0.000 0.010 0.010 decoder.py:2(<module>)
1 0.000 0.000 0.000 0.000 random.py:40(<module>)
424 0.000 0.000 0.000 0.000 {isinstance}
40/22 0.000 0.000 0.004 0.000 sre_parse.py:307(_parse_sub)
1 0.000 0.000 0.012 0.012 __init__.py:98(<module>)
14 0.000 0.000 0.003 0.000 sre_compile.py:367(_compile_info)
3 0.000 0.000 0.000 0.000 sre_compile.py:264(_mk_bitmap)
1 0.000 0.000 0.000 0.000 collections.py:1(<module>)
1 0.000 0.000 40.276 40.276 {execfile}
165 0.000 0.000 0.000 0.000 sre_parse.py:144(append)
140 0.000 0.000 0.000 0.000 sre_parse.py:132(__len__)
192 0.000 0.000 0.000 0.000 sre_parse.py:201(match)
26 0.000 0.000 0.001 0.000 sre_compile.py:184(_compile_charset)
22 0.000 0.000 0.004 0.000 sre_parse.py:669(parse)
1 0.000 0.000 0.001 0.001 encoder.py:2(<module>)
1 0.000 0.000 0.000 0.000 {method 'bind' of 'zmq._zmq.Socket' objects}
1 0.000 0.000 0.000 0.000 threading.py:57(_Verbose)
12 0.000 0.000 0.006 0.001 re.py:229(_compile)
14 0.000 0.000 0.009 0.001 sre_compile.py:501(compile)
101 0.000 0.000 0.000 0.000 sre_parse.py:96(__init__)
1 0.000 0.000 0.000 0.000 scanner.py:3(<module>)
137 0.000 0.000 0.000 0.000 {ord}
26 0.000 0.000 0.000 0.000 sre_compile.py:360(_simple)
15 0.000 0.000 0.000 0.000 sre_parse.py:231(_class_escape)
2 0.000 0.000 0.005 0.002 scanner.py:18(__init__)
14 0.000 0.000 0.006 0.000 sre_compile.py:486(_code)
74 0.000 0.000 0.000 0.000 sre_compile.py:24(_identityfunction)
16 0.000 0.000 0.000 0.000 sre_parse.py:263(_escape)
32 0.000 0.000 0.000 0.000 {method 'format' of 'str' objects}
26 0.000 0.000 0.000 0.000 sre_compile.py:480(isstring)
22 0.000 0.000 0.000 0.000 sre_parse.py:184(__init__)
14 0.000 0.000 0.000 0.000 {_sre.compile}
56 0.000 0.000 0.000 0.000 {method 'get' of 'dict' objects}
24 0.000 0.000 0.000 0.000 sre_parse.py:73(__init__)
15 0.000 0.000 0.000 0.000 sre_parse.py:78(opengroup)
15 0.000 0.000 0.000 0.000 sre_parse.py:89(closegroup)
26 0.000 0.000 0.000 0.000 sre_parse.py:140(__setitem__)
33 0.000 0.000 0.000 0.000 {max}
32 0.000 0.000 0.000 0.000 {chr}
1 0.000 0.000 0.000 0.000 {method 'socket' of 'zmq._zmq.Context' objects}
1 0.000 0.000 0.000 0.000 warnings.py:45(filterwarnings)
1 0.000 0.000 0.002 0.002 decoder.py:244(JSONDecoder)
1 0.000 0.000 0.000 0.000 __future__.py:48(<module>)
1 0.000 0.000 0.000 0.000 threading.py:412(Thread)
1 0.000 0.000 0.000 0.000 bisect.py:1(<module>)
12 0.000 0.000 0.006 0.001 re.py:188(compile)
32 0.000 0.000 0.000 0.000 {method 'setdefault' of 'dict' objects}
10 0.000 0.000 0.000 0.000 {range}
1 0.000 0.000 0.000 0.000 traceback.py:1(<module>)
1 0.000 0.000 0.000 0.000 {function seed at 0xb7732f7c}
5 0.000 0.000 0.004 0.001 scanner.py:65(decorator)
1 0.000 0.000 0.000 0.000 {math.exp}
1 0.000 0.000 0.000 0.000 {posix.open}
1 0.000 0.000 0.000 0.000 random.py:99(seed)
1 0.000 0.000 0.000 0.000 random.py:71(Random)
11 0.000 0.000 0.000 0.000 {method 'extend' of 'list' objects}
1 0.000 0.000 0.000 0.000 threading.py:424(__init__)
1 0.000 0.000 0.000 0.000 keyword.py:11(<module>)
14 0.000 0.000 0.000 0.000 {method 'items' of 'dict' objects}
1 0.000 0.000 0.000 0.000 threading.py:737(__init__)
1 0.000 0.000 0.000 0.000 os.py:747(urandom)
15 0.000 0.000 0.000 0.000 {method 'remove' of 'list' objects}
12 0.000 0.000 0.000 0.000 {_sre.getlower}
1 0.000 0.000 0.000 0.000 {posix.read}
1 0.000 0.000 0.000 0.000 threading.py:374(set)
2 0.000 0.000 0.000 0.000 {math.log}
1 0.000 0.000 0.000 0.000 threading.py:288(notifyAll)
7 0.000 0.000 0.000 0.000 __future__.py:75(__init__)
1 0.000 0.000 0.000 0.000 threading.py:364(__init__)
1 0.000 0.000 0.000 0.000 Queue.py:17(Queue)
1 0.000 0.000 0.000 0.000 {binascii.hexlify}
1 0.000 0.000 0.000 0.000 encoder.py:87(JSONEncoder)
1 0.000 0.000 0.000 0.000 random.py:90(__init__)
3 0.000 0.000 0.000 0.000 {built-in method acquire}
1 0.000 0.000 0.000 0.000 threading.py:177(_Condition)
2 0.000 0.000 0.000 0.000 {method 'setter' of 'property' objects}
1 0.000 0.000 0.000 0.000 threading.py:270(notify)
1 0.000 0.000 0.000 0.000 encoder.py:119(__init__)
1 0.000 0.000 0.000 0.000 threading.py:357(Event)
5 0.000 0.000 0.000 0.000 scanner.py:64(pattern)
1 0.000 0.000 40.276 40.276 <string>:1(<module>)
1 0.000 0.000 0.000 0.000 random.py:643(WichmannHill)
1 0.000 0.000 0.000 0.000 {posix.close}
1 0.000 0.000 0.000 0.000 random.py:793(SystemRandom)
1 0.000 0.000 0.000 0.000 decoder.py:276(__init__)
1 0.000 0.000 0.000 0.000 threading.py:776(_DummyThread)
1 0.000 0.000 0.000 0.000 threading.py:219(_is_owned)
1 0.000 0.000 0.000 0.000 Queue.py:212(PriorityQueue)
1 0.000 0.000 0.000 0.000 threading.py:99(_RLock)
1 0.000 0.000 0.000 0.000 threading.py:360(_Event)
3 0.000 0.000 0.000 0.000 sre_parse.py:213(seek)
1 0.000 0.000 0.000 0.000 scanner.py:17(Scanner)
3 0.000 0.000 0.000 0.000 sre_parse.py:211(tell)
1 0.000 0.000 0.000 0.000 {math.sqrt}
1 0.000 0.000 0.000 0.000 threading.py:503(_set_ident)
1 0.000 0.000 0.000 0.000 threading.py:64(_note)
1 0.000 0.000 0.000 0.000 threading.py:706(_Timer)
2 0.000 0.000 0.000 0.000 {thread.get_ident}
2 0.000 0.000 0.000 0.000 {built-in method release}
1 0.000 0.000 0.000 0.000 {method 'insert' of 'list' objects}
1 0.000 0.000 0.000 0.000 __future__.py:74(_Feature)
1 0.000 0.000 0.000 0.000 Queue.py:9(Empty)
1 0.000 0.000 0.000 0.000 Queue.py:231(LifoQueue)
1 0.000 0.000 0.000 0.000 threading.py:735(_MainThread)
1 0.000 0.000 0.000 0.000 threading.py:345(_BoundedSemaphore)
1 0.000 0.000 0.000 0.000 threading.py:297(_Semaphore)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
1 0.000 0.000 0.000 0.000 {issubclass}
1 0.000 0.000 0.000 0.000 {posix.getpid}
1 0.000 0.000 0.000 0.000 threading.py:745(_set_daemon)
1 0.000 0.000 0.000 0.000 Queue.py:13(Full)
import os, sys, zmq
pid = os.getpid()
transform = lambda data: str(pid)
c = zmq.Context()
s = c.socket(zmq.REP)
s.bind('tcp://0.0.0.0:12000')
for i in xrange(100000):
data = s.recv_multipart()
data[-1] = transform(data[-1])
s.send_multipart(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment