java foreach Iterator 性能差别
来源:互联网 发布:ardupilot 源码下载 编辑:程序博客网 时间:2024/06/05 02:13
package com.bp.test;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* 关于map的测试
* @author current_bp
* @createTime 20161111
*/
public class MapTest {
public static void main(String[] args) {
// MapTest.mapGetEachValue();
MapTest.mapGetEachValue2();
}
public static void mapGetEachValue(){
Map<String, String> map = new HashMap<>();
for(int i=0;i<100000;i++){
map.put("bp"+i, "baopan"+i);
}
Long time1 = System.currentTimeMillis();
for(String key : map.keySet()){
System.out.println("key:"+key+" value:"+map.get(key));
}
Long time2 = System.currentTimeMillis();
System.out.println("allTime:"+(time2 - time1));
//count:10000,valueCount:8,avg:144.875,allResult:[153,118,117,207,91,110,95,268]
//count:100000,valueCount:8,avg:989.5,allResult:[977,969,1002,1091,949,1116,956,856]
}
public static void mapGetEachValue2(){
Map<String, String> map = new HashMap<>();
for(int i=0;i<100000;i++){
map.put("bp"+i, "baopan"+i);
}
Long time1 = System.currentTimeMillis();
Iterator<String> iter = map.keySet().iterator();
String key = null;
while(iter.hasNext()){
key = iter.next();
System.out.println("key:"+key+" value:"+map.get(key));
}
Long time2 = System.currentTimeMillis();
System.out.println("allTime2:"+(time2 - time1));
//count:10000,valueCount:8,avg:138.375,allResult:[129,132,83,128,256,106,105,168]
//count:100000,valueCount:8,avg:965.875,allResult:[957,912,720,1116,958,977,1069,1018]
}
}
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* 关于map的测试
* @author current_bp
* @createTime 20161111
*/
public class MapTest {
public static void main(String[] args) {
// MapTest.mapGetEachValue();
MapTest.mapGetEachValue2();
}
public static void mapGetEachValue(){
Map<String, String> map = new HashMap<>();
for(int i=0;i<100000;i++){
map.put("bp"+i, "baopan"+i);
}
Long time1 = System.currentTimeMillis();
for(String key : map.keySet()){
System.out.println("key:"+key+" value:"+map.get(key));
}
Long time2 = System.currentTimeMillis();
System.out.println("allTime:"+(time2 - time1));
//count:10000,valueCount:8,avg:144.875,allResult:[153,118,117,207,91,110,95,268]
//count:100000,valueCount:8,avg:989.5,allResult:[977,969,1002,1091,949,1116,956,856]
}
public static void mapGetEachValue2(){
Map<String, String> map = new HashMap<>();
for(int i=0;i<100000;i++){
map.put("bp"+i, "baopan"+i);
}
Long time1 = System.currentTimeMillis();
Iterator<String> iter = map.keySet().iterator();
String key = null;
while(iter.hasNext()){
key = iter.next();
System.out.println("key:"+key+" value:"+map.get(key));
}
Long time2 = System.currentTimeMillis();
System.out.println("allTime2:"+(time2 - time1));
//count:10000,valueCount:8,avg:138.375,allResult:[129,132,83,128,256,106,105,168]
//count:100000,valueCount:8,avg:965.875,allResult:[957,912,720,1116,958,977,1069,1018]
}
}
1 0
- java foreach Iterator 性能差别
- Java中的foreach性能差别
- java之foreach&Iterator
- java 遍历 Iterator foreach for
- java 集合遍历Iterator/foreach
- iterator & foreach
- java和javascript的for,foreach,iterator
- java迭代器Iterator和foreach循环
- java学习笔记-foreach与iterator
- Java基础8:Iterator和foreach循环
- s:iterator与c:forEach标签性能分析
- for和foreach差别
- Java类集--Iterator接口、ListIterator接口、foreach及Enumeration接口
- Java学习笔记(34)----------Iterator、Collection接口以及foreach
- java基础:关于遍历 -- for 、foreach 和 Iterator
- C++/Java性能差别如此大?
- Iterator和foreach循环
- foreach for Iterator 区别
- XML-Range解析
- STM32单片机串口下载程序的简单原理和设置
- jquery 数组合并
- 关于数据采集
- [转] 先验概率 后验概率 似然 极大似然估计 极大后验估计 共轭 概念
- java foreach Iterator 性能差别
- Java_servlet_配置文件
- Windows服务编写综述
- moveTaskToback退后台
- Eclipse中创建新的Spring Boot项目
- POJ 1005-I Think I Need a Houseboat
- SAP修改消息内容和报错类型(SE91和OBA5)
- 【支付宝服务窗】JEECG支付宝服务窗平台指南
- Spark -3:三种集群模式