与 Java 相比,Scala 的性能如何? [英] How well does Scala perform compared to Java?

查看:42
本文介绍了与 Java 相比,Scala 的性能如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题实际上说明了一切.

The Question actually says it all.

这个问题背后的原因是我即将开始一个小的副项目,并想在 Scala 中完成它.过去一个月我正在学习 Scala,现在我很舒服地使用它.scala 编译器本身非常慢(除非您使用 fsc).那么它在 JVM 上的表现如何呢?我以前在 groovy 上工作过,我看到有时比 java 表现得更好.我的问题是与 Java 相比,Scala 在 JVM 上的表现如何.我知道 scala 有一些非常好的特性(FP、动态语言、静态类型……)但归根结底我们需要性能……

The reason behind this question is I am about to start a small side project and want to do it in Scala. I am learning scala for the past one month and now I am comfortable working with it. The scala compiler itself is pretty slow (unless you use fsc). So how well does it perform on JVM? I previously worked on groovy and I had seen sometimes over performed than java. My Question is how well scala perform on JVM compared to Java. I know scala has some very good features(FP, dynamic lang, statically typed...) but end of the day we need the performance...

推荐答案

我的大部分工作都使用 Scala 作为一种高性能语言.如果真的非常关注性能,Scala 几乎总是和 Java 一样好(如果不是等价的).如果一个人不小心,例如对象创建,它可能会更糟——就像在 Java 中,如果你使用一个不关心对象创建的库.(事实上​​,我的 Scala 代码通常比我的 Java 代码快,因为我发现让我的高度优化的代码更易于使用和重用——但是如果我有更多的时间和耐心.)

A majority of my work uses Scala as a high-performance language. If one really pays careful attention to performance, Scala is almost always nearly as good as Java (if not equivalent). If one is careless about e.g. object creations, it can be many times worse--as it can in Java if you use a library that is careless about object creations. (In fact, my Scala code is often faster than my Java code because I find it so much easier to make my highly optimized code convenient to use and reuse--but the Java would be as fast or faster if only I had more time and patience.)

如果您想要一些数据来证明 Scala 基本上可以和 Java 一样快,请查看 计算机语言基准游戏.(对于高吞吐量多核编程,另一个不太有用但仍然有趣的比较是 Tim Bray 的 Wide Finder 2.这个不太有用,因为算法没有预先定义,所以很大一部分差异归结为算法的差异.)

If you want some data that demonstrates that Scala can be basically as fast as Java, check out the results on the Computer Languages Benchmark Game. (Another less useful but still interesting comparison for high-throughput multicore programming is Tim Bray's Wide Finder 2. This is less useful because the algorithm is not defined in advance, so a large portion of the differences boil down to differences in algorithm.)

这篇关于与 Java 相比,Scala 的性能如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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