Sun, 26 Jun 2005 08:35:58 +0200 skrev Peter Otten: > Steven D'Aprano wrote: > >> On Sat, 25 Jun 2005 21:30:26 +0200, Peter Otten wrote: >> >>> Mandus wrote: >>> >>>> By using the builtin reduce, I >>>> move the for-loop into the c-code which performs better. >>> >>> No. There is no hope of ever writing fast code when you do not actually >>> measure its performance. >> >> Good grief! You've been spying on Mandus! How else could you possibly know >> that he doesn't measure performance? Are you running a key-logger on his >> machine? *wink* > > His mentioning reduce() as a performance panacea was a strong indication > even without looking over his shoulders. He filled in some conditions in a > later post, but "[U]sing reduce ... performs better [than a for-loop]" is > just wrong.
Ok - so sometimes reduce() for convenience (nha, that's just me...), sometimes for performance. In some cases clever use of map/reduce/etc. have given a good speedup - say 4 times that of for-loops. But going to C can give 10 to 100 times speed up over that again... So it depends how important the performance is. Going to C/Fortran is always a bit more hassel, while reduce is something you can stick in your interactive session to finish the work rather before than after lunch :) [snip] > >> Isn't it reasonable to just say, "I use join because it is faster than >> adding strings" without being abused for invalid optimization? > > OK, I am making a guess: "".join(strings) is more often faster than > naive string addition than reduce() wins over a for-loop. you're probably right. > I don't think my pointed comment qualifies as "abuse", by the way. neither think I. -- Mandus - the only mandus around. -- http://mail.python.org/mailman/listinfo/python-list