Skip to content

Commit

Permalink
✅ Adding tests.hashmap concurrenthashmap 写入性能对比。
Browse files Browse the repository at this point in the history
  • Loading branch information
crossoverJie committed Nov 15, 2018
1 parent f4bde51 commit 0e6366d
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class RouteActionTest {

Expand Down Expand Up @@ -56,4 +57,26 @@ public void reflect3(){
}
}


@Test
public void costTest(){
Map<Integer,Integer> hashmap = new HashMap<>(16);
long start = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
hashmap.put(i,i) ;
}
long end = System.currentTimeMillis();
LOGGER.info("hashmap cost time=[{}] size=[{}]",(end -start),hashmap.size());

hashmap=null;


Map<Integer,Integer> concurrentHashMap = new ConcurrentHashMap<>(16);
start = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
concurrentHashMap.put(i,i) ;
}
end = System.currentTimeMillis();
LOGGER.info("hashmap cost time=[{}] size=[{}]",(end -start),concurrentHashMap.size());
}
}

0 comments on commit 0e6366d

Please sign in to comment.