Skip to content

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++.

Notifications You must be signed in to change notification settings

bonj4/LoopPyBinder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic Pybind Usage

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++.

Files

  1. forloop.cpp: C++ source code that defines a simple loop function.
  2. forloop_w_default.py: Python script that demonstrates loop function without Pybind11.
  3. forloop_w_pybind.py: Python script that uses the loop function exposed through Pybind11.
  4. so.cpp: Pybind11 module source code that binds the C++ loop function for use in Python.
  5. CMakeLists.txt: CMake file for building the project.
  6. 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.

Installing Dependencies

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

Build Instructions

Make sure you have CMake installed.

mkdir build
cd build
cmake ..
make

Running Tests

1. C++ Loop (Once and 10 Times)

g++ forloop.cpp

2. Python Loop (Once and 10 Times)

python forloop_default.py

3. Python with Pybind Loop (Once and 10 Times)

python forloop_w_pybind.py

Testing Results

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.

C++ Loop

C++ Loop Result

Python Loop

Python Loop Result

Python with Pybind Loop

Pybind Loop Result

Notes

  • 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.

About

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++.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published