diff --git a/protocol/src/test/java/com/zfoo/protocol/collection/ConcurrentTesting.java b/protocol/src/test/java/com/zfoo/protocol/collection/ConcurrentTesting.java index 563f6008..abbb1550 100644 --- a/protocol/src/test/java/com/zfoo/protocol/collection/ConcurrentTesting.java +++ b/protocol/src/test/java/com/zfoo/protocol/collection/ConcurrentTesting.java @@ -14,13 +14,14 @@ package com.zfoo.protocol.collection; import com.zfoo.protocol.collection.concurrent.ConcurrentHashMapLongObject; import com.zfoo.protocol.collection.concurrent.CopyOnWriteHashMapLongObject; +import io.netty.util.collection.LongObjectHashMap; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; +import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; -import java.util.function.BiConsumer; /** * @author godotg @@ -213,4 +214,56 @@ public class ConcurrentTesting { System.out.println(System.currentTimeMillis() - startTime); } + + + // ----------------------------------------------------------------------------------------------------------------- + @Test + public void primitiveMapTest() { + var map = new LongObjectHashMap<>(); + var startTime = System.currentTimeMillis(); + + for (int count = 0; count < maxCount; count++) { + for (int j = 0; j < num; j++) { + map.put(j, j); + } + for (var entry : map.entries()) { + var key = entry.key(); + var value = entry.value(); + } + for (int j = 0; j < num; j++) { + var value = (int) map.get((long) j); + Assert.assertEquals(value, j); + } + for (int j = 0; j < num; j++) { + map.remove((long) j); + } + } + + System.out.println(System.currentTimeMillis() - startTime); + } + + @Test + public void mapTest() { + var map = new HashMap(); + var startTime = System.currentTimeMillis(); + + for (int count = 0; count < maxCount; count++) { + for (int j = 0; j < num; j++) { + map.put((long) j, j); + } + for (var entry : map.entrySet()) { + var key = entry.getKey(); + var value = entry.getValue(); + } + for (int j = 0; j < num; j++) { + var value = (int) map.get((long) j); + Assert.assertEquals(value, j); + } + for (int j = 0; j < num; j++) { + map.remove((long) j); + } + } + + System.out.println(System.currentTimeMillis() - startTime); + } }