Skip to content

Add benchmarks for C function call overhead of various alternatives #370

Open
@mdboom

Description

@mdboom

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 with PyArg_ParseTuple
  • extension_manunpack: Python/C API with PyArg_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:

image

  1. 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.
  2. SWIG adds a Python wrapper around everything, so it's not surprising it sees the most significant speedup in 3.11
  3. There seems to be a regression in ctypes, which is maybe concerning...?

Metadata

Metadata

Assignees

Labels

benchmarkingAnything related to measurement: Adding new benchmarks, benchmarking infrastructure etc.

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions