List problem
Josiah Carlson
jcarlson at uci.edu
Mon Nov 1 02:13:18 EST 2004
bokr at oz.net (Bengt Richter) wrote:
> delsome_br
> 3.39048024526
> 3.63548729364
> 3.6326486655
> delsome_am
> 6.40547292869
> 6.32403355062
> 6.21752171923
FYI: list comprehensions in 2.4 are significantly faster than list
comprehensions in 2.3, which is likely where a large portion of your
difference is coming from.
I wasn't sure that I believed your statements in regards to Python's
cache performance, so I thought I'd give it a look...
Python 2.3.2 (#49, Oct 2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a = range(1000000)
>>> import time
>>> def f(a):
... t = time.time()
... for i in a:
... pass
... return time.time()-t
...
>>> for i in xrange(10):
... print f(a),
...
0.421999931335 0.421000003815 0.421999931335 0.422000169754 0.421999931335 0.437
99996376 0.421000003815 0.421999931335 0.43799996376 0.406000137329
>>> import random
>>> random.shuffle(a)
>>> for i in xrange(10):
... print f(a),
...
0.594000101089 0.59299993515 0.610000133514 0.608999967575 0.608999967575 0.5940
00101089 0.593999862671 0.608999967575 0.594000101089 0.593999862671
>>> a.sort()
>>> for i in xrange(10):
... print f(a),
...
0.421999931335 0.421999931335 0.421999931335 0.422000169754 0.43700003624 0.4219
99931335 0.421999931335 0.421999931335 0.422000169754 0.43700003624
Looks to be an almost 50% slowdown on my dual celeron 400mhz machine
(128kb cache). Very interesting, I would have never have expected as
much (due to the amount of overhead of Python data structures, I
believed it was generally a wash).
- Josiah
More information about the Python-list
mailing list