r/Python • • 15m ago

News I Built A C++ Powered Python Library Using pybind11 - way faster than python loops

Hey everyone, I just published my first C++ powered Python library on PyPI (kaptandanuj-easyhelper) to see how much faster list operations get when you move the loop from Python to C++.

Right now it has an order-preserving unique() function for int, float, and str lists. Under the hood it uses a templated C++ std::vector + std::unordered_set with reserve() pre-allocation, bound with pybind11.

On a list of 100k items, it beats a normal Python for loop + set()

Here how you install it

pip install kaptandanuj-easyhelper

0 Upvotes

1 comment sorted by

•

u/PLPeeters 0m ago

Not to burst your bubble, but did you benchmark it against list(dict.fromkeys(items)) instead of an explicit Python loop?

dict.fromkeys() is already implemented in C in CPython, preserves insertion order, and avoids the Python-to-C++ type conversion overhead introduced by pybind11.