JAVA的ArrayList和LinkedList速度简单测试
结论:测试10万个Integer对象,发现随机查询,随机插入ArrayList比LinkedList快,快好多倍,jdk1.8
控制台输出结果:
StopWatch 'watch0': running time (millis) = 48963
-----------------------------------------
ms % Task name
-----------------------------------------
00044 000% arrayList第一个一万条花费时间(随机插入)
00030 000% arrayList第2个10000条随机插入花费时间
00034 000% arrayList第3个10000条随机插入花费时间
00040 000% arrayList第4个10000条随机插入花费时间
00050 000% arrayList第5个10000条随机插入花费时间
00247 001% arrayList第6个10000条随机插入花费时间
00071 000% arrayList第7个10000条随机插入花费时间
00082 000% arrayList第8个10000条随机插入花费时间
00067 000% arrayList第9个10000条随机插入花费时间
00073 000% arrayList第10个10000条随机插入花费时间
00105 000% linkedList第一个1万条花费时间(随机插入)
00548 001% linkedList第2个10000条随机插入花费时间
00982 002% linkedList第3个10000条随机插入花费时间
01304 003% linkedList第4个10000条随机插入花费时间
02070 004% linkedList第5个10000条随机插入花费时间
03381 007% linkedList第6个10000条随机插入花费时间
04811 010% linkedList第7个10000条随机插入花费时间
06750 014% linkedList第8个10000条随机插入花费时间
10559 022% linkedList第9个10000条随机插入花费时间
11722 024% linkedList第10个10000条随机插入花费时间
00246 001% arrayList随机查询
05747 012% linkedList随机查询
00181 000% linkedList循环遍历1
05765 010% linkedList循环遍历2
00211 000% linkedList迭代器遍历
代码:
package demo.xxc;
import cn.hutool.core.util.RandomUtil;
import org.springframework.util.StopWatch;
import java.util.ArrayList;
import java.util.LinkedList;
public class Test001 {
public static void main(String[] args) {
StopWatch watch0 = new StopWatch("watch0");
m3(watch0);
System.out.println(watch0.prettyPrint());
}
private static void m1(StopWatch watch0) {
watch0.start("arrayList花费时间(尾部添加)");
ArrayList