Clojure 数字运算性能 [英] Clojure number crunching performance
问题描述
我不确定这是否属于 StackOverflow 或 Clojure Google 群组.但该组似乎正忙于讨论 Clojure 1.2 的数值改进,所以我会在这里尝试:
I'm not sure whether this belongs on StackOverflow or in the Clojure Google group. But the group seems to be busy discussing numeric improvements for Clojure 1.2, so I'll try here:
http://shootout.alioth.debian.org/ 有许多性能基准各种语言.
http://shootout.alioth.debian.org/ has a number of performance benchmarks for various languages.
我注意到 Clojure 不见了,所以我制作了 n 体问题.
I noticed that Clojure was missing, so I made a Clojure version of the n-body problem.
我能够生成的最快的代码可以是 在这里找到,并且基准测试似乎是说Clojure对于数字运算是
The fastest code I was able to produce can be found here, and benchmarking it seems to be saying that for number crunching Clojure is
- 比 Python/Ruby/Perl 快 10 倍
- 比 C/Java/Scala/Ada 慢 4 倍
- 与 OCaml、Erlang 和 Go 大致相当
我对这种水平的表现很满意.
I'm quite happy with that level of performance.
我对 Clojure 专家的问题是
My question to the Clojure gurus is
- 我是否遗漏了一些明显的改进,无论是在速度方面,还是在代码简洁性或可读性方面(不牺牲速度)?
- 您是否认为这是 Clojure 性能与 Python/Ruby/Perl 和 Java/C 的代表?
更新
有关枪战的更多 Clojure 1.1 基准程序此处,包括 n 体问题.
More Clojure 1.1 benchmark programs for the shootout here, including the n-body problem.
推荐答案
这里的回复不是很多 :) 但显然有些兴趣,所以我将尝试用我在过去几年中学到的知识来回答我自己的问题天:
Not a flood of responses here :) but apparently some interest, so I'll try to answer my own question with what I've learned over the past few days:
- 使用 1.1 优化方法(Java 原语和可变数组)比优化后的 Java 慢约 4 倍,但与它的运行速度差不多.
- 1.2 构造
definterface
和deftype
快两倍多,是 Java 的约 1.7 倍(+70%)与 1.1 相比,代码更短、更简单、更干净.
- With the 1.1 optimization approach (Java primitives and mutable arrays) ~4x slower than optimized Java is about as fast as it goes.
- The 1.2 constructs
definterface
anddeftype
are more than twice as fast, coming within ~1.7x (+70%) of Java with shorter, simpler and cleaner code than for 1.1.
以下是实现:
更多详情,包括经验教训"、JVM 版本和分析屏幕截图.
More details including "lessons learned", JVM version and profiling screenshots.
主观上来说,优化 1.2 代码比优化 1.1 轻而易举,所以这对于 Clojure 数字运算来说是一个非常好的消息.(实际上接近惊人:)
Subjectively speaking, optimizing the 1.2 code was a breeze compared to optimizing 1.1, so this is very good news for Clojure number crunching. (Actually close to amazing :)
1.2 测试使用了当前的 master 分支,我没有尝试任何新的数字分支.从我能收集到的目前正在讨论的新想法
The 1.2 testing used the current master branch, I did not try any of the new numeric branches. From what I can gather the new ideas currently being discussed
- 可能会使未优化的数字更快
- 可能会加快此基准测试的 1.1 版本
- 可能不会加快 1.2 版本的速度,它已经接近金属"了.
免责声明:
- Clojure 1.2 尚未发布,因此 1.2 基准测试结果是初步的.
- 这是物理计算的一项特殊基准.它与浮点数运算相关,但与字符串解析、并发或 Web 请求处理等领域的性能无关.
这篇关于Clojure 数字运算性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!