I got a great speedup using C++ with pybind11 for my Python backend, 30x if I remember correctly. It was for an app that detects wether words rhyme. I was about to release it but ditched it as soon as ChatGPT came out (it can find rhymes easily, and sometimes better).
There's nanobind by the same author as pybind11 that's even faster: https://github.com/wjakob/nanobind
Swig – Connect C/C++ programs with high-level programming languages
11–20 of 90 posts
Re: Swig – Connect C/C++ programs with high-level programming languages
#12Re: Swig – Connect C/C++ programs with high-level programming languages
#13In my personal experience, to use a very small C library in python in a work project, my life became simpler when I ditched swig and just called the C API from python. Then I had a pure python codebase that I could run on any python version without recompilation, and I no longer had the complication of having to deal with swig's different versions across different distribution releases. For much bigger projects I cou…
How do you call C API from python? Through executable + stdin/stdout?
Re: Swig – Connect C/C++ programs with high-level programming languages
#14Re: Swig – Connect C/C++ programs with high-level programming languages
#15I've used Swig for C++ to Python interop and let me warn you it is a nightmare. The syntax is absurdly terse and convoluted, documentation sucks and good luck trying to search the web for constructs made only of special characters. CLIF is way nicer for C++/Python. If you need other languages then best of luck (Zig, Rust and D are easier than Java and Go at least).
Re: Swig – Connect C/C++ programs with high-level programming languages
#16I've used Swig for C++ to Python interop and let me warn you it is a nightmare. The syntax is absurdly terse and convoluted, documentation sucks and good luck trying to search the web for constructs made only of special characters. CLIF is way nicer for C++/Python. If you need other languages then best of luck (Zig, Rust and D are easier than Java and Go at least).
Re: Swig – Connect C/C++ programs with high-level programming languages
#17If you're just targetting python, and it's your first venture into building python extensions, it's fantastic. After a while, it's worth trying out building an extension without the use of swig. Much of the time, it's easier to use than swig is - but you do have to implement all the bells and whistles yourself. If you're writing in C or C++, chances are you like that kind of thing anyway.
Re: Swig – Connect C/C++ programs with high-level programming languages
#18I don't think this is the right way: interop with the C ABI, and for the hercules who want to do that with c++, should be native to such programming languages, not from a project on the side.
Re: Swig – Connect C/C++ programs with high-level programming languages
#19Re: Swig – Connect C/C++ programs with high-level programming languages
#20I'm always impressed on how simple it is to use an object I defined in c within python.