#! /usr/bin/python #import pycallgraph from time import clock from threading import Thread from multiprocessing import Process, Queue # multiprocessing.queues (v.2.6.4) + pickle_suggestion_v2.patch from queues_pickled import Queue as newQueue ITERATIONS = 10000 def populateQueue(q): l = list(xrange(1000)) for i in xrange(ITERATIONS): q.put(l) if __name__ == '__main__': #pycallgraph.start_trace() for child in (None, Thread, Process): print "\n", str(child), "\n----" for index, q in enumerate((Queue(), Queue(), newQueue(), newQueue(bufferPickled = True))): if child: p = child(target = populateQueue, args = (q,)) t1 = clock() p.start() for i in xrange(ITERATIONS): q.get() t2 = clock() p.join() else: t1 = clock() populateQueue(q) for i in xrange(ITERATIONS): q.get() t2 = clock() print ("%.3f" % round(t2 - t1, 3)), str(q.__class__), if index != 3: print else: print "(bufferPickled = True)" #pycallgraph.make_dot_graph('result.png')