[Chicago] who's faster than who?
skip at pobox.com
Sat Dec 24 03:31:17 CET 2005
Peter> ... replacing lists with tuples (16% faster for slicing!) ...
This difference exists in 2.3, but not in 2.4 or CVS (2.5a0).
Peter> ... generator comprehensions are *much* faster than lambda + imap
Hmmm... Your tuple/list statement suggests you are using 2.3, but generator
expressions aren't available until 2.4, even after importing
all_feature_names from __future__. For the simpleminded test I tried, generator
expressions were no faster than list comprehensions:
% python2.4 ~/local/bin/timeit.py 'for x in ((y*y) for y in xrange(10000)): x'
100 loops, best of 3: 1.32e+04 usec per loop
% python2.4 ~/local/bin/timeit.py 'for x in [(y*y) for y in xrange(10000)]: x'
100 loops, best of 3: 1.31e+04 usec per loop
In general, I would suggest that the appropriate data structure be chosen
(e.g, list vs tuple, set vs dict) unless absolutely necessary.
Peter> 3. Asking your boss to cut you a check for every machine you
Peter> don't need to buy b/c you've optimized your code is unlikely to
Peter> yield satisfactory results. ;)
I work in a trading firm. Computers are fixed costs, while the profit they
generate is ongoing and directly related to the number and speed of the
computers. It's rarely difficult to decide to buy more hardware or upgrade
More information about the Chicago