Any suggestions?

Jon Ribbens jon+python-list at
Mon Sep 25 11:50:56 CEST 2000

Simon Brunning <SBrunning at> wrote:
> See <> (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:


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)


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?



More information about the Python-list mailing list