test[map]: primitive map test

This commit is contained in:
godotg
2023-12-11 15:12:24 +08:00
parent f260996922
commit d0b1acf35a
@@ -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<Long, Integer>();
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);
}
}