Why is this loop heavy code so slow in Python? Possible Project Euler spoilers

Mark Dickinson dickinsm at gmail.com
Sun Sep 2 13:42:23 EDT 2007


On Sep 2, 12:55 pm, al... at mac.com (Alex Martelli) wrote:
> Mark Dickinson <dicki... at gmail.com> wrote:
> > Well, for one thing, you're creating half a million xrange objects in
> > the course of the search.  All the C code has
> > to do is increment a few integers.
>
> I don't think the creation of xrange objects is a meaningful part of
> Python's execution time here.  Consider:
> [...]

Agreed---I just came to the same conclusion after doing some tests.
So maybe it's the billion or so integer objects being created that
dominate the running time?  (Not sure how many integer objects
actually are created here: doesn't Python cache *some* small
integers?)

Mark





More information about the Python-list mailing list