Reputation: 1053
i have prepared a project in python language ie a TEXT TO SPEECH synthesizer. Which took a total on 1500 lines of code. But there few parts of code due to which it is taking so much time to run the code, i want to replace that parts of code in C/c++ lang so that it runs faster.
So i want to know how can i run these parts of code in C++ or improve its speed in any other way??
please suggest,
Upvotes: 0
Views: 134
Reputation: 5555
You could also try effect of psyco module to your code's running time (Python 2.6 or earlier) or pypy (python JIT written in subset python). There is also C++ compiler shedskin, Windows is not supported in latest versions though.
Upvotes: 0
Reputation: 375484
You have a few options:
As Radomir mentioned, Cython might be a good choice: it's essentially a restricted Python with type declarations, automatically translated into C then compiled for execution.
If you want to use pure C, you can write a Python extension module using the Python C API. This is a good way to go if you need to manipulate Python data structures in your C code. Using the Python C API, you write in C, but with full access to the Python types and methods.
Or, you can write a pure C dll, then invoke it with ctypes
. This is a good choice if you don't need any access to Python data structures in your C code. With this technique, your C code only deals with C types, and your Python code has to understand how to use ctypes to get at that C data.
Upvotes: 3
Reputation: 2585
You could write them in Cython, it's pretty easy.
Alternatively, you can try using numpy, which is already written in C and may have most of the operations you need.
Upvotes: 5