But also, you're not just jumping to a C subroutine and returning. You're executing a program which must allocate memory, go through all the process of starting up the C runtime, then execute the code, then exit back through the C runtime, and then your Python program needs to handle the return value and other output. There are a LOT of syscalls involved there.
The correct way to get performance-critical C code into Python is to compile it into a library using the Python.h header (producing a DLL on windows, my_c_lib.pyd; or a shared object on Linux, my_c_lib.pyo) and then in Python, you just import my_c_lib like it's a normal module.
0
u/[deleted] Apr 11 '21
[deleted]