Performance of Boost Python

百般思念 提交于 2019-12-07 05:36:07

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/12281855/performance-of-boost-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!