Java-> Scala,收藏表演 [英] Java -> Scala, performances on collections

查看:67
本文介绍了Java-> Scala,收藏表演的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,根据集合的用法,我们不使用相同的实现(即ArrayList与LinkedList)。

In Java, according to the usage of a collection, we do not use the same implementation (ie ArrayList vs LinkedList).

来自Java背景,可以有人告诉我我应该如何了解Scala集合和性能注意事项?

Coming from a Java background, can someone tell me what should I know about Scala collections and performance considerations?

似乎Scala List的不可变版本是某种不可变的LinkedList。
我理解了Martin Odersky在Coursera上的课程之后的概念。
我以同样的方式理解为什么添加前缀比添加前缀更有效,尤其是当您拥有不可变的列表时。

It seems the immutable version of Scala List is some kind of immutable LinkedList. I understand the concepts, following Martin Odersky courses on Coursera. In the same way i understand why it's more efficient to prepend than to append, particularly when you have an immutable list.

我想知道所有( (或大多数)关于Scala集合表演的这类棘手的事情,因此我自己并不觉得困难。有人可以帮我吗?

I would like to know all (or most) of these kind of tricky things about Scala collection performances, so that I do not find it myself the hard way. Can someone help me?

谢谢

推荐答案

有一个文档描述了集合性能特征。除此之外,您确实应该在微基准测试中测试用例。在某些情况下,Scala集合的性能与Java集合非常接近。在其他地方则存在差距(例如地图);在其他版本中,没有Java类似物,并且不可变与可变比较在很大程度上取决于您使用集合的方式(显然,重度突变有利于可变集合,而重用/复制则有利于不可变集合)。

There's a document that describes collection performance characteristics. Beyond that, you really should test your use case in a microbenchmark. In some cases, Scala collections are very close in performance to Java ones; in others there's a gap (e.g. maps); in others there is no Java analog and the immutable vs. mutable comparison depends very highly on how you use the collection (with, obviously, heavy mutation favoring mutable collections, and heavy re-use/copying favoring immutable collections).

这篇关于Java-> Scala,收藏表演的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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