Concerns about performance w/Python, Pysco on Pentiums

Michael Hudson mwh at python.net
Fri Mar 7 09:04:31 EST 2003


CezaryB <cezary at bigfoot.com> writes:

> Tuples are faster then lists. Try this:

You sure about that?

/>> def f(l, i, n):
|..     from time import time
|..     r = xrange(n)
|..     T = time()
|..     for o in r:
|..         pass
|..     t0 = time() - T
|..     T = time()
|..     for o in r:
|..         l[i] # 1
|..         l[i] # 2
|..         l[i] # 3
|..         l[i] # 4
|..         l[i] # 5
|..         l[i] # 6
|..         l[i] # 7
|..         l[i] # 8
|..         l[i] # 9
|..         l[i] # 10
|..     t1 = time() - T - t0
|..     return t1/n/10
\__ 
->> listtime = f(range(1000), 500, int(1e6))
->> tupletime = f(tuple(range(1000)), 500, int(1e6))
->> print listtime, tupletime, tupletime/listtime - 1.0
2.08104205132e-07 2.37756896019e-07 0.142489628543

So simple subscription seems to be ~14% slower for tuples.

This is Python from CVS of about a week ago, fwiw.

Cheers,
M.

-- 
 Have you considered downgrading your arrogance to a reasonable level?
        -- Erik Naggum, comp.lang.lisp, to yet another C++-using troll




More information about the Python-list mailing list