将 Scala 可变、不可变集合与 java.util.concurrent.* 集合进行比较的微基准测试
是否有已发布的微基准在多线程环境中比较 Scala 可变和不可变集合以及 java.util.concurrent
中的集合?我对读者数量远远多于作者的情况特别感兴趣,例如在服务器端代码中缓存 HashMap。
Clojure 集合的微基准也是可以接受的,因为它们的算法与 Scala 2.8 持久集合中使用的算法类似。
如果还没有完成的话,我会自己编写,但是编写良好的微基准并非易事。
Are there any published micro-benchmarks that compare the Scala mutable and immutable collections with each other and the collections in java.util.concurrent
, in multi-threaded environments? I am particularly interested in cases where readers far outnumber writers, like caching HashMaps in server-side code.
Micro-benchmarks of the Clojure collections would also be acceptable, as their algorithms are similar to those used in the Scala 2.8 persistent collections.
I'll write my own if there are none already done, but writing good micro-benchmarks is not trivial.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里有一些比较 Java 哈希映射、Scala 哈希映射、Java 并发哈希映射、Java 并发跳跃列表、Java 并行数组和 Scala 并行集合的结果(在技术报告的末尾):
http://infoscience.epfl.ch/record/165523/files/techrep.pdf
有此处对并发跳过列表和 Java 并发哈希映射进行更详细的比较(也在报告主要部分的末尾,附录之前):
http://infoscience.epfl.ch/record/166908/files/ctries-techreport.pdf
这些微观基准测试专注于测试单个操作的性能。如果您打算编写自己的基准测试,这可能会很有用:
http://buytaert.net/文件/oopsla07-georges.pdf
There are some results comparing Java hash maps, Scala hash maps, Java concurrent hash maps, Java concurrent skip lists, Java parallel arrays and Scala parallel collections here (at the end of the technical report):
http://infoscience.epfl.ch/record/165523/files/techrep.pdf
There is a more detailed comparison of concurrent skip lists and Java concurrent hash maps here (also at the end of the main part of the report, before the appendix):
http://infoscience.epfl.ch/record/166908/files/ctries-techreport.pdf
These micro benchmarks are focused on testing the performance of one single operation. If you plan to write your own benchmarks, this will probably be useful:
http://buytaert.net/files/oopsla07-georges.pdf
Lihaoyi 的Benchmarking Scala Collections 是一项详细而全面的研究,可以解决您的疑问。这里引用太长了。
Li Haoyi's Benchmarking Scala Collections is a detailed and comprehensive study that addresses your query. It is way too long to quote here.
那么为什么不尝试使用 java.util.concurrent.ConcurrentHashMap 呢?这样您就不必同步,并且您的一百万次读取将会快得多(以及一次写入)。
Why don't you try using java.util.concurrent.ConcurrentHashMap then? that way you don't have to synchronize, and your million reads will be much faster (as well as the one write).