Simple repo serving as a basic template showing how to quickly bind other programming languages to python.
This project demonstrates parallel square root computation using three different approaches:
- Python: Using multiprocessing
- C++: Using pybind11 with std::async
- Rust: Using PyO3 with rayon
Sample outcome on my local device:
=== Python (multiprocessing) ===
Time: 237.20ms
=== C++ (pybind11) ===
Time: 0.46ms
=== Rust (PyO3) ===
Time: 0.61ms
- Python 3.8+
- uv (Python package manager)
- C++ compiler (for C++ bindings)
- Rust and Cargo (for Rust bindings)
uv syncuv run python setup.py build_ext --inplaceThis will create cpp_bindings.cp3xx-*.pyd in the project root.
uv run maturin develop --releaseuv run python main.pyThis will compare the performance of all three implementations.
python-bindings/
├── main.py # Main benchmark script
├── cpp_bindings.cpp # C++ implementation
├── rust_src/
│ └── lib.rs # Rust implementation
├── setup.py # C++ build configuration
├── Cargo.toml # Rust build configuration
└── pyproject.toml # Python project configuration
- Modern C++ bindings for Python
- Uses std::async for parallel execution
- Thread pool based on hardware concurrency
- Safe Rust bindings for Python
- Uses rayon for data parallelism
- Compiled with release optimizations
⚠️ This project usesuvfor package management as seen inpyproject.toml. The C++ and Rust implementations are compiled extensions that must be built before use. The build artifacts (.pydfiles on Windows,.sofiles on Unix) are gitignored and must be rebuilt after cloning.