Guido's regrets: filter and map

Alex Martelli aleax at aleax.it
Mon Nov 25 05:53:36 EST 2002


Dennis Lee Bieber wrote:
   ...
>         Well, to add some more embers... Two runs under Mandrake 8.2, on a
> 733MHz P-III with RDRAM (Dell XPS B733r), Python 2.2, using the program
> listed above.
> 
> [wulfraed at beastie wulfraed]$ python t.py
> for loop took 7.61 to make a list of 500000 items
> list comprehension took 7.30 to make a list of 500000 items
> map took 6.84 to make a list of 500000 items
> [wulfraed at beastie wulfraed]$ python t.py
> for loop took 7.61 to make a list of 500000 items
> list comprehension took 7.31 to make a list of 500000 items
> map took 6.85 to make a list of 500000 items

And Mandrake 9.0, 1.33 GHz AMD Athlon, and 266-MHz DDR :

[alex at lancelot alex]$ python2.2 -O aa.py
for loop took 2.87 to make a list of 500000 items
list comprehension took 2.75 to make a list of 500000 items
map took 2.47 to make a list of 500000 items
[alex at lancelot alex]$ python2.3 -O aa.py
for loop took 2.33 to make a list of 500000 items
list comprehension took 2.32 to make a list of 500000 items
map took 1.61 to make a list of 500000 items
[alex at lancelot alex]$ python2.2 -O aa.py
for loop took 2.79 to make a list of 500000 items
list comprehension took 2.66 to make a list of 500000 items
map took 2.45 to make a list of 500000 items
[alex at lancelot alex]$ python2.3 -O aa.py
for loop took 2.32 to make a list of 500000 items
list comprehension took 2.34 to make a list of 500000 items
map took 1.61 to make a list of 500000 items
[alex at lancelot alex]$

Using time.clock instead of time.time it's quite similar:

[alex at lancelot alex]$ python2.2 -O aa.py
for loop took 2.80 to make a list of 500000 items
list comprehension took 2.67 to make a list of 500000 items
map took 2.45 to make a list of 500000 items
[alex at lancelot alex]$ python2.2 -O aa.py
for loop took 2.79 to make a list of 500000 items
list comprehension took 2.67 to make a list of 500000 items
map took 2.47 to make a list of 500000 items
[alex at lancelot alex]$ python2.3 -O aa.py
for loop took 2.32 to make a list of 500000 items
list comprehension took 2.34 to make a list of 500000 items
map took 1.61 to make a list of 500000 items
[alex at lancelot alex]$ python2.3 -O aa.py
for loop took 2.33 to make a list of 500000 items
list comprehension took 2.32 to make a list of 500000 items
map took 1.62 to make a list of 500000 items
[alex at lancelot alex]$


Alex




More information about the Python-list mailing list