Boost Python的性能 [英] Performance of Boost Python

查看:199
本文介绍了Boost Python的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目,我正在试验boost python。在研究如何组织我的python界面时,我遇到了一个评论,断言有boost python的性能问题。是否有任何实际关注它的性能?

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?

在这种情况下,我正在使用一个大项目,我们想要暴露一些它到python。我发现boost python使我很容易暴露我已经有的类。所以我宁愿坚持使用boost python的方法暴露类,因为它很容易。

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.

推荐答案

如果你的用例需要很多回调函数并在Python和C ++之间在一个严格的循环中,那么Boost.Python可能是一个性能问题,至少相对于直接使用Python C-API的手动滚动包装器。很难猜测它是否会比类似用户友好的东西更差,比如SWIG。

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.

但是最大的性能问题是你是否可以避免这种来回 - 一个可以避免跨越C ++ / Python障碍的API通常总是比执行的更好,不管使用什么库或包装器工具。大多数情况下,这意味着将循环从Python移植到C ++,避免在这些循环中使用Python回调,尤其是Python到C ++类型的转换。

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.

这篇关于Boost Python的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆