Feature suggestion: sum() ought to use a compensated summation algorithm

Raymond Hettinger python at rcn.com
Mon May 5 04:16:42 EDT 2008


> > > However I find the seccond argument hack ugly. Does the sum way have any
> > > performance advantages over the reduce way?
>
> > Yes, sum() is faster:
...

> Not really; you measure the import and the attribute access time in
> the second case. sum() is 2x faster for adding numbers only:

Try it with Py2.6 or Py3.0.  The sum() function has been optimized and
should be at least 6x faster for summing ints and floats.  It should
even beat psyco optimized sums!


Raymond



More information about the Python-list mailing list