OK, you won. I read in an (regretably old) guidline for improving Python's performance that you should prefer map() compared to list comprehensions. Apparently the performance of list comprehensions has improved a lot, which is great. (Or the overhead of calling map() got too big, but I hope this is not the case.) So, what is the purpose of map()? Should it too be deprecated?

Andreas

Skip Montanaro wrote:

   Andreas> Yeeh, I was expecting something like that. The only reason to
   Andreas> use map() at all is for improving the performance.  That is
   Andreas> lost when using list comprehensions (as far as I know). So,
   Andreas> this is *no* option for larger jobs.

Did you test your hypothesis?

   % python -m timeit -s 'lst = ("abc"*10).split() ; import string' 
'map(string.upper, lst)'
   100000 loops, best of 3: 9.24 usec per loop
   % python -m timeit -s 'lst = ("abc"*10).split()' '[s.upper() for s in lst]'
   100000 loops, best of 3: 4.18 usec per loop
   % python -m timeit -s 'lst = ("abc"*100).split() ; import string' 
'map(string.upper, lst)'
   100000 loops, best of 3: 16.1 usec per loop
   % python -m timeit -s 'lst = ("abc"*100).split()' '[s.upper() for s in lst]'
   100000 loops, best of 3: 10.8 usec per loop
   % python -m timeit -s 'lst = ("abc"*1000).split() ; import string' 
'map(string.upper, lst)'
   10000 loops, best of 3: 72.7 usec per loop
   % python -m timeit -s 'lst = ("abc"*1000).split()' '[s.upper() for s in lst]'
   10000 loops, best of 3: 67.7 usec per loop
   % python -m timeit -s 'lst = ("abc"*10000).split() ; import string' 
'map(string.upper, lst)'
   1000 loops, best of 3: 844 usec per loop
   % python -m timeit -s 'lst = ("abc"*10000).split()' '[s.upper() for s in 
lst]'
   1000 loops, best of 3: 828 usec per loop

   % python -m timeit -s 'lst = ["abc"*10]*10 ; import string' 
'map(string.upper, lst)'
   10000 loops, best of 3: 42.7 usec per loop
   % python -m timeit -s 'lst = ["abc"*10]*10' '[s.upper() for s in lst]'
   10000 loops, best of 3: 26.5 usec per loop
   % python -m timeit -s 'lst = ["abc"*10]*100 ; import string' 
'map(string.upper, lst)'
   1000 loops, best of 3: 376 usec per loop
   % python -m timeit -s 'lst = ["abc"*10]*100' '[s.upper() for s in lst]'
   1000 loops, best of 3: 230 usec per loop
   % python -m timeit -s 'lst = ["abc"*10]*1000 ; import string' 
'map(string.upper, lst)'
   100 loops, best of 3: 3.72 msec per loop
   % python -m timeit -s 'lst = ["abc"*10]*1000' '[s.upper() for s in lst]'
   100 loops, best of 3: 2.23 msec per loop

The above results are using Python CVS (aka 2.5a0).

Skip




-- http://mail.python.org/mailman/listinfo/python-list

Reply via email to