[Python-checkins] python/nondist/sandbox/collections timedeque.py, NONE, 1.1

rhettinger at projects.sourceforge.net rhettinger at projects.sourceforge.net
Mon Jan 26 11:23:20 EST 2004


Update of /cvsroot/python/python/nondist/sandbox/collections
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8098

Added Files:
	timedeque.py 
Log Message:
Measure performance of deques

--- NEW FILE: timedeque.py ---
from timeit import Timer

setup = """
from deque import deque
init = range(100)
d = deque(init)
l = list(init)
da = d.append
la = l.append
dp = d.pop
lp = l.pop
dpl = d.popleft
dal = d.appendleft
from itertools import chain
def irange(x):
    for i in xrange(x):
        yield i
big = irange(1000)
"""

tests = [
    'la(1)',            # Buildup through appends
    'da(1)',
    'la(1); lp()',      # Steady state stack
    'da(1); dp()',
    'dal(1); dpl()',
    'la(1); lp(0)',     # Steady state queue
    'da(1); dpl()',
    'dal(l); dp()',
]

longtests = [
    'list(xrange(1000))',# Constructor source len known
    'deque(xrange(1000))',
    'list(irange(100))',# Constructor source len unknown
    'deque(irange(100))',
    'min(l)',           # iter
    'min(d)',
]

for test in tests:
    t = min(Timer(test, setup).repeat(5))
    print '%.3f\t%s' % (t, test)

for test in longtests:
    t = min(Timer(test, setup).repeat(5, 10000))
    print '%.3f\t%s' % (t, test)




More information about the Python-checkins mailing list