饮料包装机的速度

发布于 2024-10-08 02:00:25 字数 103 浏览 0 评论 0原文

如果我用 c++ 编写几个类,然后使用 swig 进行转换,以便以后可以在 python 中使用它们,那么它们会比我在 python 中完全重写它们运行得更快或更慢吗?或者没有明显的速度差异?

If I were to write several classes in c++ then use swig to do the conversion so I could later use them in python, would they run faster or slower than if I completely rewrote them in python? Or is there no noticable speed difference?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

归属感 2024-10-15 02:00:27

SWIG 生成的包装纸的质量和速度非常好,它们的性能可能与手工制作的包装纸一样好。

根据我的经验,包装器本身非常薄,并且给它们包装的本机函数添加了很少的开销,这使得在 python 或任何其他受支持的语言中使用包装库成为一个完全有效的选择,并且是重用代码的好方法。

然而,如果您除了代码重用之外还对性能感兴趣,那么包装本机代码可能只有在您拥有一些计算密集型本机函数(例如矩阵相乘、计算 MD5 或 CRC、折叠蛋白质等)时才会有回报

。 ,有时您可以用 python 或 C# 等简单语言重写所有内容,并享受更好的代码和更好的工具,以及相当的性能。

The quality and speed of wrappers generated by SWIG is very good, and they will probably perform just as good as handcrafted wrappers.

From my experience, the wrappers themselves are very thin and add very little overhead to the native functions they wrap, making it a perfectly valid choice to use wrapped libraries in python or any other supported language, and is a good way to reuse code.

however, to be if you are interested in performance in addition to code reuse, wrapping native code will probably only pay off if you have some computationally intensive native functions, like multiplying matrices, computing MD5 or CRC, folding proteins etc.

on the other hand, sometimes you can just rewrite everything in an easy language like python or C# and enjoy better code and better tools, with comparable performance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文