Convert Python program to C/C++ code?

Convert Python program to C/C++ code?

If the C variant needs x hours less, then Id invest that time in letting the algorithms run longer/again

invest isnt the right word here.

  1. Build a working implementation in Python. Youll finish this long before youd finish a C version.

  2. Measure performance with the Python profiler. Fix any problems you find. Change data structures and algorithms as necessary to really do this properly. Youll finish this long before you finish the first version in C.

  3. If its still too slow, manually translate the well-designed and carefully constructed Python into C.

    Because of the way hindsight works, doing the second version from existing Python (with existing unit tests, and with existing profiling data) will still be faster than trying to do the C code from scratch.

This quote is important.

Thompsons Rule for First-Time Telescope Makers
It is faster to make a four-inch mirror and then a six-inch mirror than to make a six-inch mirror.

Bill McKeenan
Wang Institute

Yes. Look at Cython. It does just that: Converts Python to C for speedups.

Convert Python program to C/C++ code?

Shed Skin is a (restricted) Python-to-C++ compiler.

Leave a Reply

Your email address will not be published. Required fields are marked *