arraylist-lambada-性能测试
Posted mrerror
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了arraylist-lambada-性能测试相关的知识,希望对你有一定的参考价值。
package cn.com.one;
import java.util.ArrayList;
public class ttt {
public static void main(String [] args) {
new Thread(()->{
Thread.currentThread().setName("t2");
int k =0;
String test2 = "";
long startTime2 = System.currentTimeMillis();
ArrayList<Object> arrayList2= new ArrayList<>(10);
while(true){
k += 1;
test2 = "我是第"+k+"个";
arrayList2.add(test2);
if(k > 10000000) break;
}
long overTime2 = System.currentTimeMillis();
System.out.println(Thread.currentThread().getName()+(overTime2 - startTime2) / 1000+"s");
}).start();
//----------------------------------------------------------------------------------------------------
Runnable runnable = ()->{
Thread.currentThread().setName("t1");
int j =0;
String test1 = "";
long startTime1 = System.currentTimeMillis();
ArrayList<Object> arrayList1 = new ArrayList<>(100);
while (true) {
j += 1;
test1 = "我是第" + j + "个";
arrayList1.add(test1);
if (j > 10000000) break;
}
long overTime1 = System.currentTimeMillis();
System.out.println(Thread.currentThread().getName()+(overTime1 - startTime1) / 1000 + "s");
};
//----------------------------------------------------------------------------------------------------
Thread.currentThread().setName("tmain");
int i =0;
String test0 = "";
long startTime0 = System.currentTimeMillis();
ArrayList<Object> arrayList0= new ArrayList<>(1);
while(true){
i += 1;
test0 = "我是第"+i+"个";
arrayList0.add(test0);
if(i > 10000000) break;
}
long overTime0 = System.currentTimeMillis();
System.out.println(Thread.currentThread().getName()+(overTime0 - startTime0) / 1000+"s");
//----------------------------------------------------------------------------------------------------
}
}
以上是关于arraylist-lambada-性能测试的主要内容,如果未能解决你的问题,请参考以下文章