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

Mark Dickinson dickinsm at gmail.com
Sun Sep 2 10:10:31 EDT 2007


On Sep 2, 9:45 am, jwrweather... at gmail.com wrote:
> [snip code]
>
> Thanks for that. I realise that improving the algorithm will speed
> things up. I wanted to know why my less than perfect algorithm was so
> much slower in python than exactly the same algorithm in C. Even when
> turning off gcc's optimiser with the -O0 flag, the C version is still
>
> > 100 times quicker.

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.

Mark




More information about the Python-list mailing list