Clojure数字处理性能 [英] Clojure number crunching performance

查看:93
本文介绍了Clojure数字处理性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是否属于StackOverflow或Clojure Google群组。但该小组似乎忙于讨论 Clojure 1.2的数值改进,所以我会在这里尝试:



http://shootout.alioth.debian.org/ 有多种不同语言的性能基准。



我注意到Clojure缺失了,所以我制作了一个Clojure版本的 n-body问题



我能够生成的最快的代码可以在此处找到,以及基准测试似乎是说,对于数字解开Clojure是




  • 比Python / Ruby / Perl快10倍

  • 系数比C / Java / Scala / Ada慢约4倍

  • 大约与OCaml,Erlang和Go相似

$



我对Clojure大师的问题是



b

  • 在速度或代码简洁性或可读性方面(不牺牲速度),我是否有明显的改进?

  • 你认为这是代表Clojure性能与Python / Ruby / Perl和Java / C在另一方面吗?



更新



更多Clojure 1.1基准测试程序这里,包括n体问题。

解决方案

洪水的响应在这里:),但显然有些兴趣,所以我会尽力回答我自己的问题,我在过去几天学到了:




  • 使用1.1优化方法(Java原语和可变数组)比优化的Java慢4倍的速度与它的速度一样快。

  • 1.2结构 definterface deftype 快速,进入Java的约1.7倍(+ 70%),比1.1更短,更简单和更干净的代码。



以下是实施方式:





更多详情,包括课程学习,JVM版本和剖析屏幕截图。



主观上说,优化1.2代码比优化1.1更容易,所以这是Clojure数字处理非常好的消息。 (实际上接近惊人:)



1.2测试使用当前主分支,我没有尝试任何新的数字分支。




  • 可能会使非优化的数字更快。

  • 可能会加快这个基准的1.1版本

  • 可能不会加快1.2版本,它已经是接近金属,因为它可能得到。 >


免责声明:




  • Clojure 1.2尚未发布,因此1.2基准测试结果是初步的。

  • 这是物理计算的一个特定基准。它与浮点数数字处理相关,但与字符串解析,并发或Web请求处理等领域的性能无关。


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/ has a number of performance benchmarks for various languages.

I noticed that Clojure was missing, so I made a Clojure version of the n-body problem.

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

  • factor ~10 quicker than Python/Ruby/Perl
  • factor ~4 slower than C/Java/Scala/Ada
  • approximately on par with OCaml, Erlang and Go

I'm quite happy with that level of performance.

My question to the Clojure gurus is

  • Are there obvious improvements I have missed, either in terms of speed or in terms of code brevity or readability (without sacrificing speed)?
  • Do you consider this to be representative of Clojure performance vs Python/Ruby/Perl on one hand and Java/C on the other?

Update

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:

  • 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 and deftype are more than twice as fast, coming within ~1.7x (+70%) of Java with shorter, simpler and cleaner code than for 1.1.

Here are the implementations:

More details including "lessons learned", JVM version and profiling screenshots.

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 :)

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

  • may make non-optimized numerics faster
  • may speed up the 1.1 version of this benchmark
  • will probably not speed up the 1.2 version, it is already as "close to the metal" as it is likely to get.

Disclaimers:

  • Clojure 1.2 is not released yet, so 1.2 benchmark results are preliminary.
  • This is one particular benchmark on physics calculations. It is relevant to floating point number crunching, but irrelevant to performance in areas like string parsing, concurrency or web request handling.

这篇关于Clojure数字处理性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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