Favorite non-python language trick?
__peter__ at web.de
Sat Jun 25 23:19:48 CEST 2005
> 25 Jun 2005 13:15:16 -0700 skrev Devan L:
>> But by using the builtin reduce, you need to specify a function, which
>> probably slows it down more than any speed-up from the loop in C.
> Sounds reasonable, but not always the case, especially when dealing with
> numpy arrays. At least that what some of my test shows. But then I
> should probably write c-functions that deals with the numeric arrays
> Besides, functions like 'operator.add' is also in c, maybe that helps.
Yes, the C-coded operator.mul() was the counterexample that John Lenton came
up with when I challenged the speed advantage of reduce() over the
> But I admit it's not a perfect example.
Python is more about readability than raw speed, and I prefer a for-loop
over reduce() in that respect, too. If you need the best possible
efficiency you would probably have to code the loop in C. Incidentally, for
add() this has already been done with the sum() builtin.
More information about the Python-list