4 ms·
Does anyone know how well Python and Rust team up compared to Python and C in practice?
by Rotareti 8y ago
Does anyone know how well Python and Rust team up compared to Python and C in practice?
- ikornaselur 8y agoI've yet to play with beyond just experimenting a little bit, but it seems it works very well. I've mainly been looking at these resources: https://github.com/rochacbruno/rust-python-example https://github.com/rochacbruno/rust-python-example https://github.com/PyO3/pyo3 https://github.com/PyO3/pyo3 Though I have not done rust <-> python in real practice
- jwandborg 8y agoSubjectively I'm really impressed by PyO3. If you care about speed, Rust is supposedly as fast as C. The Rust ecosystem also has a lot of supposedly safe(!) tools for parallelism.
- gpm 8y agoI've done it once, converting about 15 lines of python to rust. It was completely painless and resulted in a large speedup (changed a hotspot that was taking approximately 90% of execution time in a scientific simulation to approximately 0%). Type system and expressive macros seems like a big win over c to me.
- quietbritishjim 8y agoCare to share a bit more detail on how you did this? Was there some interfacing library that you used analogous to Cython/SWIG/etc.? Presumably you didn't code directly against the C API (in python.h)?
- gpm 8y agoThe rust library interfacing with python is https://github.com/dgrunwald/rust-cpython https://github.com/dgrunwald/rust-cpython This library understand things like python arrays, objects, etc. and provides nice rust interfaces to them. Basically I just have to write a macro that specifies what functions I'm exposing to python, and other then that I'm writing normal rust. On the python side I'm importing them and calling them like any other python library. The build system is https://github.com/PyO3/setuptools-rust https://github.com/PyO3/setuptools-rust (which is linked at the bottom of the above readme).