3 ms·
when you need to inline C code, then you use ctypes. it seems to be a common idea to use "whatever is the most fancy latest funny lib" because it's necessarily
by zobzu 14y ago
when you need to inline C code, then you use ctypes.
it seems to be a common idea to use "whatever is the most fancy latest funny lib" because it's necessarily better. (and some older well known libs which are useful but may also be rather slow)
Obviously, it's often not better, as the author mention.
In my experience with python, a lot of functions are directly mapped to C code and those are nearly as fast as well written C code.
Some others are calling python code in between, and those are obviously much slower.
That's the main thing to know when you want speed. So if you start using fancy python classes and other crap on top, it's going to be slower and slower, and if it's code that's called a lot, it's going to hurt hard.
When sometimes, some code needs to be fast and there's no functions that call C code directly, ctypes work just fine.
Now there are some libraries which are well made (performance wise), but that's not the norm. It's actually pretty damn rare in my experience.
- 16s 14y agoBoost Python is fabulous too if you want to call C++ routines. We do a lot of heavy lifting with that and use plain Python for higher-level tasks.