Any suggestions?
Jon Ribbens
jon+python-list at unequivocal.co.uk
Mon Sep 25 05:50:56 EDT 2000
Simon Brunning <SBrunning at trisystems.co.uk> wrote:
> See <http://www.musi-cal.com/~skip/python/fastpython.html> (IIRC) for some
> hints on this.
I took a look at this, and it all looks very sensible. I decided to try
out the map-versus-loops thing to see the difference, however, and I am
completely bemused by the results. Using Python 2.0b1, I tried the
following code:
import string
import sys
def func():
list = sys.stdin.readlines()
newlist = []
upper = string.upper
append = newlist.append
for word in list:
append(upper(word))
func()
When run over /usr/share/dict/words, time(1) says:
real 0m5.010s
user 0m3.992s
sys 0m0.951s
The map version:
import string
import sys
list = sys.stdin.readlines()
newlist = map(string.upper, list)
takes:
real 0m5.775s
user 0m2.893s
sys 0m2.823s
The map version is *slower*! I had expected it to be considerably faster.
I am also somewhat bemused by the increase in the 'sys' time.
What's going on?
Cheers
Jon
More information about the Python-list
mailing list