Long integers, xrange and number theory

Terry Reedy tjreedy at udel.edu
Mon Dec 9 12:43:38 EST 2002


"Michael Hudson" <mwh at python.net> wrote in message
news:7h3ptsbih9j.fsf at pc150.maths.bris.ac.uk...

> "Terry Reedy" <tjreedy at udel.edu> writes:
> > Your utility functions (wrapped reduces) would run faster if you
> > import operator and use the C-coded functions contained therein
> > instead of Python-coded lambdas.


> I've said this before, recently, but you will likely go faster with
a
> for loop. [such as, slightly clipped]

> def testf(l):
>    x = 0
>    for y in l:
>        x += y

<snip test results showing 10% speedup on one system, which may or may
not hold true on other systems>

With a 10% difference, one can usually choose on the basis of esthetic
taste (which definitely depends on the person.)  However, serious
speedup requires shifting from generic PyObject operations to unboxed
integer operations via psyco, pyrex, weave, or whatever.  For this, I
believe the loop version to be much better.  When ompiled, it might
runs 5 to 10 times faster.

Terry J. Reedy





More information about the Python-list mailing list