Archive

Archive for November, 2009

Python Speed – Performance Tips

November 30th, 2009 Frank No comments

Between my graduate studies and such, I’ve been toying around with ProjectEuler.net questions. I’ve answered some in C but most in Python as I wanted to become more competent with Python.

As I was working on a problem, I was having performance problems with my code. I Googled and had come across this. So, I wanted to post this here for reference:

http://wiki.python.org/moin/PythonSpeed/PerformanceTips

The biggest difference for meĀ  was using the xrange function over the range function. Project Euler requires you to iterate over various numbers and such, so when generating large ranges of numbers, xrange is faster… especially when you are simply creating a large range of numbers because you don’t know how high you need to go.

The other section that was also helpful was the code profiling section.

Categories: Random Tags: