简体   繁体   中英

Fastest way to call a C function from Python

Performance is really a key here. I have some C functions for numeric tasks, of double input and double output. I am looking for a highly efficient way to invoke these functions and retrieve the results. What would be the fastest solution?

Many solutions exist, such as ctypes, swig, etc. Some of these tools, eg, swig, have evolved significantly over the years and thus updated information can be helpful. To date, performance-wise, what is the best solution for calling existed C code from Python script?

[Edit] This question is related to, but different from this question . As mentioned above, I am seeking updated info whereas that post is dated on 2008. In addition, that post is about the quickest way to do to save the developer's time, and is not for application performance as I am asking here.

I would consider writing a C extension module .

This way, you can keep the most critical parts in C, you can have the compiler optimize your code as much as possible and you can avoid converting certain values to Python objects.

Cython is a nice way for writing C extensions without using C.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM