r/Python • • 11d ago

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

[removed]

0 Upvotes

6 comments sorted by

•

u/AutoModerator 9d ago

Your submission has been automatically queued for manual review by the moderation team because it has been reported too many times.

Please wait until the moderation team reviews your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

7

u/PLPeeters 11d 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.

6

u/AdMammoth8075 11d ago

Fair point!! It is significantly slower than dict.fromKeys() and my aim is not to make fastest library i just want to know the architecture behind making this type of libraries and it's my first step

0

u/[deleted] 11d ago

[removed] — view removed comment

2

u/remic_0726 11d ago

Pas toujours, trop souvent le problème se situe entre la chaise et le clavier. Et utiliser le profiler de python peut faire des miracles, même avec des anciennes versions moins véloces. D'ailleurs cela est aussi valable en micropython, une bonne optimisation des quelques lignes te fait gagner de nombreuses heures fastidieuses de codage en C, et encore le C il faut savoir l'apprivoiser, un débordement de tampon ou une fuite mémoire et la belle optimisation se transforme en cauchemar pour le néophite.