2025-09-20 –, Space 2
This talk will demonstrate how to re-write simple classes and functions in C/C++ and port them in python as a native package via Pybind11. Speed comparisons are made to showcase how refactoring certain code snippets in C can significantly benefit the algorithmic efficiency.
Python is well known for its simplicity and adaptability in accomplishing a variety of daily tasks ranging from data analysis, scientific computing to imaging processing. But every now and then, we may encounter some highly resource-intensive tasks where large-scale datasets are involved and there are millions or even billions of operations needed in order to achieve automation. Pure Python solutions, in this case, can introduce noticeable speed limitations due to interpreted execution that may lead to significant computational overhead and wait time.
While CPython, PyPy, and native Python libraries built on C/C++ architectures like NumPy and OpenCV have offered some efficient solutions for tasks like matrix operations and image feature analysis, they often come with limitations and may lack the customizability required to implement custom logic specific to the project's need.
In this talk, I will illustrate how to use Pybind11 to import custom code written in C++ as native Python functions and therefore leverage both Python's flexibility and C++'s fast performance. We will start with some basic mathematical functions (like max, min, and round) and gradually move on to more complex sorting and filtering algorithms in Python. By analysing their performance using %timeit method and re-write them in C++, we can observe the time difference in execution and demonstrate how the simplest refactoring can deliver significant speedups.
If your Python tasks are crawling under heavy computational loads, this talk will give you some ideas on how to go beyond simple Pythonic logic to supercharge code performance while keeping your solutions relatively clean and maintainable.
Intermediate
I am currently a PhD student at the Faculty of Asian and Middle Eastern Studies at the University of Cambridge. My dissertation focuses on the digitalization of Shang oracle bones stored at Cambridge University Library. In my leisure, I am also a computer science enthusiast and avid coder proficient in python, C/C++, and full-stack web technologies.