Hi Kent,

So if I undestand you right, mapping a function with map() when it is
a built-in function will/may be faster than a for loop, but if it's a
custom function (ie. a def one), it will most likely be slower?


Thanks
Bernard


On 5/13/05, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Bernard Lebel wrote:
> > The authors even go as far as saysing, on page 228 (first paragraph)
> > that map() used that way has a performance benefit and is faster than
> > a for loop.
> 
> That may well be correct, at least in the case where the function passed to 
> map is a builtin.
> Mapping a builtin to over a list is extremely fast. So write the code with a 
> for loop so it is
> clear. When you identify a performance bottleneck you can try rewriting your 
> loop using map or list
> comprehension, which is also fast. Until then it is premature optimization. 
> For typical loops over a
> small number of items I can't imagine you would notice the difference.
> 
> Kent
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to