码迷,mamicode.com
首页 > 其他好文 > 详细

arraylist-lambada-性能测试

时间:2018-12-04 22:32:13      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:ring   port   out   main   pac   str   class   测试   lis   

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-性能测试

标签:ring   port   out   main   pac   str   class   测试   lis   

原文地址:https://www.cnblogs.com/mrerror/p/10066907.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!