Python is a slightly odd language in that it is both interpreted and compiled. Well sort of. When you run it is compiled to ".pyc" bytecode - so we can quickly get bogged down in semantic details here. Hell I don't even know if what I just said is strictly accurate. But at the end of the day you want to speed things up so...
- First, use the profiler and timeit to work out where all the time is going
- Second, rewrite your pure python code to improve the slow bits you've discovered
- Third, see how it goes when optimised
- Now, depends on your scenario, but seriously think "Can I run it on a bigger CPU/memory"
- Ok, try rewriting those slow sections in C++
- Screw it, write it all in C++
If you get so far as the last option I dare say you're screwed and the savings aren't going to be significant.