Performance of Boost Python

2019-04-29 10:40发布

I working on a project where I'm experimenting with boost python. When looking into how to organize my python interface I ran into a comment that asserted there are performance concerns with boost python. Is there any actual concern with it's performance?

In this case I'm working with a large project and we want to expose some of it to python. I'm finding that boost python makes it easy to expose the classes I already have. So I would prefer to stick with boost python's methods of exposing classes because it's so easy. Unless someone has an alternative that is just as easy to use and performant.

2条回答
The star\"
2楼-- · 2019-04-29 10:55

We are using boost::python for the integration of a large computer vision library into a highly configurable software package for researchers in other fields. We didn´t ran into concerns nor problems up to know. However, we did not do any comparison tests recently.

查看更多
3楼-- · 2019-04-29 11:19

If your use case requires a lot of calls back and forth between Python and C++ in a tight loop, then Boost.Python may be a performance concern, at least relative to hand-rolled wrappers that use the Python C-API directly. It's a lot harder to guess whether it would perform any worse than something similarly user-friendly, like SWIG.

But the biggest performance question is whether you can avoid that sort of back and forth - an API that can avoid crossing the C++/Python barrier repeatedly will generally always perform better than one that does, regardless of what library or wrapper tool you use. Most often that means moving loops from Python into C++, and avoiding Python callbacks and especially Python-to-C++ type conversions within those loops.

查看更多
登录 后发表回答