我会让我的问题简短。
假设我有一个 python 程序,它从用 C/C++ 编译的 DLL 调用 C++ 代码。
-Will the speed/performance of the executing code be preserved?
假设我有一个 python 程序...绑定(bind)到 C++ 库(例如 - GTK 或 Wx)。
-Is the speed going to match that of the library as if it was compiled with a C++ program?
谢谢。
最佳答案
当Python调用C++代码时,它执行的代码是C++编译器生成的机器码。您将在接口(interface)级别付出一些代价,因为您必须将 Python 类型编码为 C++ 类型,反之亦然,但 C++ 代码本身的运行速度与从 C++ 调用时几乎相同;任何差异都是由于不同的内存使用模式导致动态分配的内存位置不同(这将导致您的 C++ 代码以不同的速度运行,具体取决于调用它的 C++ 应用程序)。
关于Python 绑定(bind);调用 C 代码和性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23288692/