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

测试Map,和list的插入效率

时间:2015-02-04 19:01:35      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

public static void count(int count) {
		System.out.println(new Date());
		List<Integer> ilist = new ArrayList<Integer>();
		for (int i = 0; i < count; i++) {
			ilist.add(i);
		}
		System.out.println(new Date());
	}
	public static void count2(int count) {
		System.out.println(new Date());
		Map<Integer, Integer> m = new HashMap<Integer, Integer>();
		for (int i = 0; i < count; i++) {
			m.put(i, i);
		}
		System.out.println(new Date());
	}
	
	public static void main(String[] args) {
	      count(9000000);
//		Wed Feb 04 17:47:58 CST 2015
//		Wed Feb 04 17:48:06 CST 2015

//		count2(9000000);
//		Wed Feb 04 17:48:24 CST 2015
//		3分多钟还没结束,就停止程序了。

//		count2(3000000);
//		Wed Feb 04 17:54:16 CST 2015
//		Wed Feb 04 17:54:17 CST 2015	
	}

经上所测试,在数据量大时,现测试大于300万时就效率好慢。







测试Map,和list的插入效率

标签:

原文地址:http://my.oschina.net/kelvinline/blog/375404

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