Created
September 19, 2013 06:24
-
-
Save smerritt/6619709 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
import benchmark | |
import Queue | |
import threading | |
import os | |
class BenchQueueStuff(benchmark.Benchmark): | |
def setUp(self): | |
self.size = 10000 | |
self.queue = Queue.Queue() | |
def test_big_batch(self): | |
for i in xrange(self.size): | |
self.queue.put(i) | |
for _ in xrange(self.size): | |
# should never block, but shit happens | |
self.queue.get(block=False) | |
def test_one_at_a_time(self): | |
for i in xrange(self.size): | |
self.queue.put(i) | |
self.queue.get() | |
def test_producer_consumer_thread(self): | |
def consume(): | |
for _ in xrange(self.size): | |
self.queue.get() | |
thr = threading.Thread(target=consume) | |
thr.daemon = True | |
thr.start() | |
for i in xrange(self.size): | |
self.queue.put(i) | |
thr.join() | |
def test_listdir(self): | |
cwd = os.getcwd() | |
for i in xrange(self.size): | |
os.listdir(cwd) | |
if __name__ == '__main__': | |
benchmark.main(each=50, numberFormat="%.4g") |
This file contains hidden or 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
Benchmark Report | |
================ | |
BenchQueueStuff | |
--------------- | |
name | rank | runs | mean | sd | timesBaseline | |
-------------------------|------|------|---------|-----------|-------------- | |
big batch | 1 | 50 | 0.04007 | 0.00197 | 1.0 | |
one at a time | 2 | 50 | 0.0401 | 0.0009213 | 1.0008963986 | |
producer consumer thread | 3 | 50 | 0.04223 | 0.004609 | 1.05394517735 | |
listdir | 4 | 50 | 0.7116 | 0.0138 | 17.7617335149 | |
Each of the above 200 runs were run in random, non-consecutive order by | |
`benchmark` v0.1.5 (http://jspi.es/benchmark) with Python 2.7.3 | |
Linux-3.2.0-53-generic-x86_64 on 2013-09-12 05:52:39. |
portante
commented
Sep 19, 2013
The previous above run lead to ... https://gist.github.com/portante/6623371
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment