I know this has been asked a thousand times, however i need to choose a library that can expose C++ functions and methods to python.
Considering my application, which mainly is a scientific (matrix) library, and python generator's matureness, support availability and performance, i have come across two options:
I have eliminated (for good or bad reasons) others options like SWIG, SIP, Pybindgen, ...
Any advice regarding those 2 library ? Any of these which would have a killer feature ?
My project has namespaces, nested classes, callbacks, and the like.
Thanks
Cython is the same speed as a carefully tuned C/C++ program; carefully tuned, Cython maps directly to C/C++. I've done many benchmarks of low level numerical code when implementing SageMath (which uses Cython for several 100K lines of code).
Performance and Speed Despite being a superset of Python, Cython is much faster than Python. It improves Python code execution speed significantly by compiling Python code into C code. The compilation further helps developers to run the Python programs smoothly without deploying additional computing resources.
Although C remains the master of speed in general, PyPy can beat C in some cases. “If you want your code to magically run faster, you should probably just use PyPy.” PyPy is less effective when our program is fast anyway or when most of the runtime is spent for calls to non-python libraries.
Note that the optimization is not always 1000 times faster for all C code, but it should be at least 10 times faster, so it is still hundreds of times faster than Python. Also bear in mind that the speed difference between C and Python varies on different code.
Considering my application, which mainly is a scientific
That pretty much means Cython. Cython was made almost specifically for that very purpose. There is a video on getting started with on from Enthought. Enthought is a company that specializes in scientific calculations.
Cython has a very good integration with Python that is unmatched by C++ or C (you would have to use #include <Python.h>
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With