什么更高性能? Haskell或OCaml [英] What's really more performant? Haskell or OCaml

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

问题描述

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



这是一个实时应用程序,我自然而然地寻找我可以获得的最佳性能。现在一些(恕我直言,非常恼人的)OCaml的支持者相对于OCaml或F#而言,对Haskell的反应相当缓慢。但根据计算机语言基准游戏,Haskell经常击败OCaml,即使只有相当小的分数 - 问题仍然存在,这个基准只接受非常具体的样本。



正确的做法当然是用两种语言来实现这个程序,然后进行比较,但是我简单地不想做双重工作。



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


<通过所有帐户,OCaml和Haskell都具有足够高性能的编译器和运行时间,几乎可以满足任何需求。在纯粹的表演基础上挑选他们对我来说似乎很愚蠢。你已经走到了这么远 - 以更清晰,更简洁,更富有表现力,更高级别的代码的名义从最明显的低级别和高性能语言(C,C ++等)中移除。那么,为什么当涉及的性能差异更小时,现在切换到那个标准呢?



我会用一些更宽泛的标准去做 - 如果您想要普及并行性,那么Haskell是更好的选择。如果你想真正普遍的变异,那么OCaml更好。



如果你最好只需要非常粗糙的并行性,并且你打算坚持大部分功能结构,在其他方面,比如语法(我认为Haskell在这里更好,但这是主观的)或可用的库(Haskell在数量/可用性方面获胜,但OCaml可能会在图形部门出现)。

我不认为你会出错两种方式

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 (IMHO quite annoying) proponent of OCaml quite frequently bitches against 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 of course implement the program in both languages and compare then, but I simply don't want to do double work.

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

解决方案

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

这篇关于什么更高性能? Haskell或OCaml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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