This project contains C++ code using Pybind11 to expose a simple loop function to Python. The goal is to compare the performance of different implementations of the loop in Python and C++.
- forloop.cpp: C++ source code that defines a simple loop function.
- forloop_w_default.py: Python script that demonstrates loop function without Pybind11.
- forloop_w_pybind.py: Python script that uses the loop function exposed through Pybind11.
- so.cpp: Pybind11 module source code that binds the C++ loop function for use in Python.
- CMakeLists.txt: CMake file for building the project.
- Images: Folder containing images illustrating the testing results for the loop function.
This project has the following dependencies:
- Pybind11: A lightweight header-only library for creating Python bindings for C++ code.
Use the provided shell script to install the dependencies. Ensure that you have the necessary build tools, such as CMake and a C++ compiler, installed on your system before running the script.
curl -sSL https://raw.githubusercontent.com/bonj4/wiki/main/pybind11_installation.sh | bash
Make sure you have CMake installed.
mkdir build cd build cmake .. make
g++ forloop.cpp
python forloop_default.py
python forloop_w_pybind.py
The Images folder contains visual representations of the testing results for each scenario. Refer to these images to analyze the performance of the different implementations.
- Ensure that you have the necessary dependencies installed.
- Feel free to modify the code for further experimentation.
- Report any issues or improvements in the Issues section.


