什么是具有队列的基本功能的最快的Java集合? [英] What is the fastest Java collection with the basic functionality of a Queue?

查看:224
本文介绍了什么是具有队列的基本功能的最快的Java集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是Java中最快的集合?



我只需要添加和删除操作,顺序不重要,equals元素不是问题,



这些集合将有Objects在内部



目前我使用ArrayDeque,因为我看到这是更快的队列实现。

解决方案

ArrayDeque 是最好的。请参阅此基准,其来自此博客帖子关于基准化此结果。 ArrayDeque 没有节点分配的开销,因为 LinkedList 没有移除数组内容的开销 ArrayList 有。在基准测试中,它为大队列执行大约 3x 以及 LinkedList ,甚至比 ArrayList 为空队列。为了获得最佳性能,您可能希望为其提供足够大的初始容量,以容纳一次可能保留的元素数量,以避免调整大小。



ArrayList LinkedList 之间,似乎它取决于队列将包含任何给定的总元素的平均数时间和 LinkedList beats ArrayList 开始于约10个元素。


What is the fastest collection in Java?

I only need the operations to add and remove, order is not important, equals elements is not a issue, nothing more than add and remove is imporant.

Without limit size is important too.

These collection will have Objects inside him.

Currently I'm using ArrayDeque because I see this is the faster Queue implementation.

解决方案

ArrayDeque is best. See this benchmark, which comes from this blog post about the results of benchmarking this. ArrayDeque doesn't have the overhead of node allocations that LinkedList does nor the overhead of shifting the array contents left on remove that ArrayList has. In the benchmark, it performs about 3x as well as LinkedList for large queues and even slightly better than ArrayList for empty queues. For best performance, you'll probably want to give it an initial capacity large enough to hold the number of elements it's likely to hold at a time to avoid many resizes.

Between ArrayList and LinkedList, it seems that it depends on the average number of total elements the queue will contain at any given time and that LinkedList beats ArrayList starting at about 10 elements.

这篇关于什么是具有队列的基本功能的最快的Java集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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