天天看点

Java中的HashMap和ConcurrentHashMap的并发性能测试

先看看代码吧,模拟1000个并发,每个测试1000次操作,循环测试10轮。分别测试put和get操作import java.util.collections;

运行结果

put time hashmapsync=3966ms.

put time concurrenthashmap=1892ms.

put time hashtable=3892ms.

get time hashmapsync=3812ms.

get time concurrenthashmap=1828ms.

get time hashtable=3985ms.

结论

concurrenthashmap的性能比同步的hashmap快一倍左右,同步的hashmap和hashtable的性能相当。

原帖地址:http://www.java2000.net/p12427