[Tutor] Python to C++
Alan Gauld
alan.gauld at btinternet.com
Thu Mar 20 18:21:52 CET 2008
"Dinesh B Vadhia" <dineshbvadhia at hotmail.com> wrote
> Say because of performance, you might want to re-write/convert
> Python code to C++. What is the best way (or best practice)
> to do this wrt the tools available?
It may be obvious but its worth noting that optimised Python may
be faster than a badly written C port. So first make sure you have
squeezed the best performance out of Python.
Secondly only rewrite the bits that need it so use the profiler to
identify the bottlenecks in your Python code and move those
to a separate module to reduce conversion effort.
After that the advice already given re pyrex/psycho etc is all good.
You might also find SWIG a useful alternative if you decide
to rewrite the slow functions by hand. SWIG will help wrap
those functions so that the remaining Python code can
access them.
Alan G.
More information about the Tutor
mailing list