首页 > 解决方案 > PyBind - Python 到 C++ 接口

问题描述

使用 PyBind 从 Python 接口和调用 C++ 代码将使 Python 代码更快是有道理的,但是对于从 C++ 调用的 Python 代码来说是否如此?

换句话说,当从 C++ 调用 Python 代码时,PyBind 是否只提供接口而不是像 Cython 那样提供性能增益?

标签: pythonc++pybind11

解决方案


First, code with pybind is NOT always faster than python, it depends on use case(example). Binding has overhead and it might take away all performance gain from calling native C++ code.

No magic happens when you call python code from С++. Same amount of work needs to be done in both cases by same machinery.


推荐阅读