/usr/share/pyshared/mx/Queue/queuebench.py is in python-egenix-mxqueue 3.2.1-1ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #! /usr/bin/python -O
""" queuebench - queue implementation benchmark
Copyright (c) 2000, Marc-Andre Lemburg; mailto:mal@lemburg.com
Copyright (c) 2000-2011, eGenix.com Software GmbH; mailto:info@egenix.com
See the documentation for further information on copyrights,
or contact the author. All Rights Reserved.
"""
import time
from mx import Queue
import UserQueue
from sys import argv, exit
try:
numtests, pushes, pops = eval(argv[1]), eval(argv[2]), eval(argv[3])
assert pushes >= pops
except:
print 'usage: queuebench.py <ntests> <pushes> <pops>, where <pushes> >= <pops>'
exit(1)
def test(reps, func):
start_cpu = time.clock()
for i in xrange(reps):
x = func()
return time.clock() - start_cpu
def method1():
x = [] # built-in list
push = x.append
for i in range(pushes): push('spam'+'i')
for i in range(pops): top = x[0]; del x[0]
def method3():
s = Queue.Queue() # Queue
push = s.push
pop = s.pop
for i in range(pushes): push('spam'+'i')
for i in range(pops): top = pop()
if 0:
def method3a():
s = Queue.Queue() # Queue
push = s.push
for i in range(pushes): push('spam'+'i')
t = s.pop_many(pops) # pop all at once
def method3b():
s = Queue.Queue() # Queue
push = s.push
for i in range(pushes): s << ('spam'+'i')
for i in range(pops): top = s >> 1
if 0:
def method3c():
s = Queue.Queue() # Queue
l = [''] * pushes
for i in range(pushes): l[i] = ('spam'+'i')
s.push_many(l)
s.pop_many(pops)
def method4():
s = UserQueue.UserQueue() # UserQueue
push = s.push
pop = s.pop
for i in range(pushes): push('spam'+'i')
for i in range(pops): top = pop()
print 'list: ', test(numtests, method1) # run func 20 tests
print 'Queue (with push + pop):', test(numtests, method3)
#print 'Queue (with push + pop_many):', test(numtests, method3a)
print 'Queue (with << + >>):', test(numtests, method3b)
#print 'Queue (with push_many + pop_many):', test(numtests, method3c)
print 'UserQueue:', test(numtests, method4)
|