Python 绑定(bind);调用 C 代码和性能

标签 python c++ dll binding module

我会让我的问题简短。

假设我有一个 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/

相关文章:

c++ - 仅用于保存 JPG 图像的简单 JPG 库(dll)?

python - Tkinter 窗口在嵌入式 python 中无响应

c++ - 无法在 C++ 中初始化 Matlab dll

python - 过滤斯坦福依存解析器输出

python - 如果或 elif 要么为真,则做某事

c++ - 了解位运算及其效果

c++ - Boost 智能指针 : Can I express it in a more concise way?

c++ - 为什么 setMainQmlFile 有效而 setSource 对同一路径失败?

python - 矩阵项也是Python中的矩阵

python - 具有不规则间隔样本的 2D 彩色图 (matplotlib.mlab.griddata)