Open
Description
It might be useful to benchmark the overhead of making C extension function calls using some of the popular approaches.
There is already a set of benchmarks available, with details in this blog post. It checks the function call overhead of the following:
extension
: Python/C API withPyArg_ParseTuple
extension_manunpack
: Python/C API withPyArg_UnpackTuple
cython
swig
boost
ctypes
I hacked around with this during the PyCon sprints, and made my own fork of these benchmarks that:
- Adds error checking to
extension_manunpack
(seems like an unfair advantage without it) - Adds a benchmark for the
METH_FASTCALL
API. - Uses the current Cython git main to have something that works with py3.11
- Uses more iterations and all of pyperf's advice for stable benchmarking.
With that, there are some interesting results:
- The benchmarks just call a C extension function 5,000,000 time in a Python loop, so for many of these, the speedup is most likely just to improved loop performance. Maybe we want to control for that.
- SWIG adds a Python wrapper around everything, so it's not surprising it sees the most significant speedup in 3.11
- There seems to be a regression in ctypes, which is maybe concerning...?
Metadata
Metadata
Assignees
Type
Projects
Status
Todo