Re: Why is this loop heavy code so slow in Python? Possible Project Euler spoilers
Mark Dickinson <dickinsm@gmail .comwrote:
Yep, some, say -5 to 100 or thereabouts; it also caches on a free-list
all the "empty" integer-objects it ever has (rather than returning the
memory for the system), so I don't think there's much optimization to be
had on that score either.
Alex
Mark Dickinson <dickinsm@gmail .comwrote:
On Sep 2, 12:55 pm, al...@mac.com (Alex Martelli) wrote:
>
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 Dickinson <dicki...@gmail .comwrote:
I don't think the creation of xrange objects is a meaningful part of
Python's execution time here. Consider:
[...]
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.
the course of the search. All the C code has
to do is increment a few integers.
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?)
all the "empty" integer-objects it ever has (rather than returning the
memory for the system), so I don't think there's much optimization to be
had on that score either.
Alex
Comment