This repository demonstrates the integration of C++ functions with Python using pybind11. It includes a Python script that tests various C++ functions exposed via the pybind11 module, including functions with no parameters, one parameter, and two parameters.
- Python 3.x
- CMake
- A C++ compiler supporting C++20
- pybind11
Follow these steps to build the pybind11 module:
-
Clone the repository and navigate to the project directory.
-
Run build script that will also run the test python script:
bash ./build.sh
-
Observe results
func_no_params: 42
func_one_param(5): 10
func_two_params(3, 4): 7
Average time per function call over 10000 calls: 0.08200949523597956 us
- Make sure your PYTHONPATH is set correctly or that the Python script is executed in an environment where the Python interpreter can locate the pybind11 module.