什么才是真正性能更高的? Haskell 或 OCaml

发布于 2024-10-05 05:41:02 字数 482 浏览 0 评论 0原文

我花了过去 18 个月的时间来掌握函数式编程,从学习 OCaml 开始,现在又花了几周时间学习 Haskell。现在我想采取下一步并实现一些实际应用:一个简单的实时地形编辑器。我已经编写了许多实时地形渲染引擎,所以这是一个熟悉的话题。并且所使用的递归算法和数据结构似乎非常适合功能实现。

由于这是一个实时应用程序,我自然会寻求可以获得的最佳性能。现在 OCaml 的一些支持者经常抱怨 Haskell 比 OCaml 或 F# 慢。但根据计算机语言基准游戏,Haskell 经常击败 OCaml,尽管只是以相当小的分数领先。仍然存在一个问题,即该基准测试仅采用非常具体的样本。

当然,正确的做法是用两种语言实现该程序并进行比较,但我只是不想做双倍的工作。

但也许其他人在 OCaml 和 Haskell 中做了类似的应用程序并给出了一些统计数据?

I spent the last 18 months getting the grip of functional programming, starting with learning OCaml and for some weeks now Haskell. Now I want to take the next step and implement some actual application: A simple realtime terrain editor. I've written numerous realtime terrain rendering engines, so this is a familiar topic. And the used recursive algorithms and data structures seem very fit for a functional implementation.

With this being a realtime application I'm naturally looking for the best performance I can get. Now some proponents of OCaml quite frequently complain about Haskell being slow compared to OCaml or F#. But according to the The Computer Language Benchmarks Game Haskell oftenly beats OCaml, if only by rather small fractions. There remains the problem, that this benchmark takes only very specific samples.

The right thing to do would be to, of course, implement the program in both languages and compare them, but I simply don't want to do double the work.

But maybe other people did comparable applications in OCaml and Haskell and give some statistics?

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

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

发布评论

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

评论(4

葬﹪忆之殇 2024-10-12 05:41:02

从各方面来看,OCaml 和 Haskell 都拥有足够高性能的编译器和运行时,几乎可以处理任何事情。在我看来,纯粹根据性能在它们之间进行选择似乎很愚蠢。您已经走到这一步了——以更清晰、更简洁、更具表现力、更高级的代码为名,远离了明显最低级和高性能的语言(C、C++ 等)。那么,当所涉及的性能差异要小得多时,为什么现在要切换到该标准呢?

我会采用一些更广泛的标准——如果你想要普遍的并行性,那么 Haskell 是更好的选择。如果您想要真正普遍的突变,那么 OCaml 会更好。

如果你最多只想要非常粗略的并行性,并且你打算坚持使用大部分功能结构,那么可以根据其他东西进行选择,比如语法(我认为 Haskell 在这里更好,但这是主观的)或可用的库(Haskell 在数量上获胜) /可用性,但 OCaml 可能会在图形部门中脱颖而出)。

我认为无论哪种方式你都不会出错

By all accounts, both OCaml and Haskell have sufficiently performant compilers and runtimes for almost anything. Picking between them on the basis of pure performance seems silly to me. You've come this far -- moving away from the obviously most low-level and performant languages (C, C++, etc.) in the name of clearer, more succinct, more expressive, higher-level code. So why, when the performance differences involved are much smaller, switch to that criteria now?

I'd go with some broader criteria -- if you want pervasive parallelism, then Haskell's the better choice. If you want genuinely pervasive mutation, then OCaml is better.

If you want only very coarse parallelism at best, and you intend to stick with mostly functional structures, then pick based on something else, like syntax (I think Haskell is much nicer here, but that's subjective) or available libraries (Haskell wins on quantity/availability, but OCaml might edge it out in the graphics department nonetheless).

I don't think you'll go wrong either way

零度℉ 2024-10-12 05:41:02

在两位非常聪明的同事的帮助下,我用 Objective Caml 和 Haskell 编写了一个数据流优化库。 Haskell 版本的多态性更强,具有更多的编译时类型检查,因此运行时检查较少。 OCaml 版本使用可变状态来累积数据流事实,本周可能会更快或更慢,具体取决于月相。关键事实是,在其预期的应用程序中,这两个库都非常快,不值得愚弄。也就是说,在各自的编译器中(Quick C--GHC),在数据流优化上花费的时间很少,因此代码不值得改进。

基准测试是地狱。

With help from two very smart colleagues, I've written a dataflow-optimization library in both Objective Caml and Haskell. The Haskell version is a bit more polymorphic, has more compile-time type checking, and therefore has less run-time checking. The OCaml version uses mutable state to accumulate dataflow facts, which might be faster or slower this week, depending on the phase of the moon. The key fact is that in their intended applications, both libraries are so fast that they are not worth fooling with. That is, in the respective compilers (Quick C-- and GHC), so little time is spent in dataflow optimization that the code is not worth improving.

Benchmarking is hell.

流云如水 2024-10-12 05:41:02

<块引用>

我编写了许多实时地形渲染引擎,所以这是一个熟悉的话题。

足够熟悉,知道大部分时间会花在哪里?

如果是这样,那么也许您可以用不同的语言为该部分编写代码并进行比较。

<块引用>

但根据计算机语言基准测试,Haskell 经常击败 OCaml,即使只是以相当小的分数 - 但仍然存在一个问题,即该基准测试仅采用非常具体的样本。

基准测试游戏报告了 4 组结果 - 一个核心和 四核,32或 64 位 Ubuntu - 您可能会发现 OCaml 或 Haskell 基准程序的性能更好或更差,具体取决于平台。

基准测试所能做的就是获取非常具体的样本,当然,您应该忽略与应用程序中大部分时间花费的任务不同的任务的比较 - 大整数算术?正则表达式?字符串? - 并查看最接近您想要做的比较。

I've written numerous realtime terrain rendering engines, so this is a familiar topic.

Familiar enough to know where most time will be spent?

If so then maybe you can write code for just that part in different languages and compare.

But according to the The Computer Language Benchmarks Game Haskell often beats OCaml, if only by rather small fractions — there remains the problem, that this benchmark takes only very specific samples.

The benchmarks game reports 4 sets of results - one core and quad core, 32 or 64 bit Ubuntu - and you may find that the OCaml or Haskell benchmark programs perform better or worse depending on the platform.

All a benchmark can do is take very specific samples, and of course you should disregard comparisons on tasks that are unlike where most time will be spent in your application - large integer arithmetic? regex? strings? - and look at the comparisons that are most like what you intend to do.

三岁铭 2024-10-12 05:41:02

根据我所看到的所有数据,它们大致具有可比性。您编写的代码将比语言本身产生更大的影响。

Based on all the data I've seen, they are roughly comparable. The code you write will make a bigger difference than the language itself.

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