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

2007-09-03 Thread jwrweatherley
Thanks for all the answers to my question. I think what I need to take away from this is that xrange is an object - I thought it was just some loop construct, and that maths is slow in python - so avoid pathological looping.I remember the first time I tried Objective-C on OS X I used the NSNumber

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

2007-09-02 Thread jwrweatherley
I'm pretty new to python, but am very happy with it. As well as using it at work I've been using it to solve various puzzles on the Project Euler site - http://projecteuler.net. So far it has not let me down, but it has proved surprisingly slow on one puzzle. The puzzle is: p is the perimeter of

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

2007-09-02 Thread jwrweatherley
[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