Michele Simionato mis6 at pitt.edu
Wed Jun 11 17:59:12 CEST 2003

pythonguy at Hotpop.com (Anand Pillai) wrote in message news:<84fc4588.0306110101.4a63666e at posting.google.com>...
> Thank you. I did not know that lambda was in fact slower
> than operator methods, but now I do. I encountered lambda's
> in lisp first, where they are preferred over direct function
> calls. Looks like python's lambda is somewhat different.
> Perhaps the language developers should re-implement it in
> C.
> Thanks
> Anand Pillai

lambdas are *NOT* slow. They have the same speed than plain
functions. Actually, internally they *are* plain functions.
Don't you believe it ? Try to profile a plain function and
an equivalent function, there is no appreciable difference.

In your case the problem is with reduce (idem for map and filter):
they are faster when you pass them a builtin function
(such as operator.add) than an user defined function.
But the slowdown is the same both for a lambda and a plain function.



More information about the Python-list mailing list