[Tutor] Compiling Python to Native Machine Code

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Sep 4 23:48:30 EDT 2003


> The type of algorithm I am using is the well known Dijkstra 
> shortest path. I 

Ah.
That is a difficult one to improve on in Python because its not 
really compute intensive but doing lots of tests and branches.

And as you navigate the graph over and over again the logic, 
even in C - even in Machine Code! - will be doing lots of 
loading and unloading of registers and branch instructions.

If you can code the algorithm in C then it will go faster, 
and probably faster than Psyco, but just how much faster 
is debateable, you are doing something that just plain 
takes a lot of time.

The first thing to do is use Python to optimise the design 
of the proposed function so that its easy to port to C and 
profile it to see just how much of the total time is in 
that functon. Divide that time by 5-10 and that's roughly 
what you should see the C version doing. If that isn't a 
big chunk of the total you may be better sticking in Python 
after all.

Alan G.



More information about the Tutor mailing list