用于编写与 Python 接口的快速抽象的语言选择?

发布于 2024-10-03 03:32:29 字数 292 浏览 4 评论 0原文

我目前有一个用 Python 编写的系统,可以分为后端层和前端层。 Python 太慢了,所以我想用快速编译的语言重写后端,同时保留 Python 中的前端,以便从 Python 调用后端功能。这样做的最佳选择是什么?

我考虑过 cython 但它的功能非常有限且编写起来很麻烦,而且速度也没有那么快。根据我对 Boost Python for C++ 的记忆,维护语言之间的桥梁非常烦人。还有更好的选择吗?

我的主要因素是:

  • 的执行速度是声明性的
  • 编译
  • 语言

I have a system currently written in Python that can be separated into backend and frontend layers. Python is too slow, so I want to rewrite the backend in a fast compiled language while keeping the frontend in Python, in a way that lets the backend functionality be called from Python. What are the best choices to do so?

I've considered cython but it's very limited and cumbersome to write, and not that much faster. From what I remember of Boost Python for C++, it's very annoying to maintain the bridge between languages. Are there better choices?

My main factors are:

  • speed of execution
  • speed of compilation
  • language is declarative

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

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

发布评论

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

评论(3

渡你暖光 2024-10-10 03:32:29

C++ 与 SWIG 可以生成您需要的所有粘合代码。只要你避免在 C++ 和 python 之间过度跳转,它就会和你的 C++ 一样快。 SWIG 接口的生成通常相当简单,除非您正在做一些“奇怪”的事情。

C++ with SWIG can generate all of the glue code you need. So long as you avoid excessive jumps between C++ and python it'll be as fast as your C++. SWIG interfaces are usually fairly straightforward to generate unless you're doing something "odd".

手心的海 2024-10-10 03:32:29

如果您使用 Jython,您可以轻松(简单地)调用 Java 后端例程。我上次检查时,Java 的速度大约是 c 的两倍,比 python 快 10 倍。

If you used Jython you could call into Java back-end routines easily (trivially). Java's about twice as slow as c and 10x faster than python last time I checked.

允世 2024-10-10 03:32:29

我不同意 Boost::Python。当包装现有的以 C++ 为中心的库并尝试不更改接口时,它可能会变得很麻烦。但这不是您想要做的。

您希望将现有 Python 解决方案的繁重工作推向更快的语言。这意味着您可以控制界面。

如果你控制着接口,你可以保持它对 python 友好,并且对 bp 友好(即:避免像指针和不可变类型这样有问题的东西作为左值)

在这种情况下,Boost::Python 可以像下面这样简单:告诉它你想从 python 调用哪些函数。

I would disagree about Boost::Python. It can get cumbersome when wrapping an existing c++-centric library and trying not to change the interface. But that is not what you are looking to do.

You are looking to push the heavy lifting of an existing python solution in to a faster language. That means that you can control the interface.

If you are in control of the interface, you can keep it python-friendly, and bp-friendly (IE: avoid problematic things like pointers and immutable types as l-values)

In that case, Boost::Python can be as simple as telling it which functions you want to call from python.

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