From c55d6d0d640ef583a76c3c92d58fbfdb0fc87510 Mon Sep 17 00:00:00 2001 From: Simon Goller Date: Mon, 12 Apr 2010 22:38:23 +0200 Subject: IntIntHashMap changed to LongIntHashMap. --- .../com/jogamp/common/util/LongIntHashMapTest.java | 139 +++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 test/junit/com/jogamp/common/util/LongIntHashMapTest.java (limited to 'test/junit') diff --git a/test/junit/com/jogamp/common/util/LongIntHashMapTest.java b/test/junit/com/jogamp/common/util/LongIntHashMapTest.java new file mode 100644 index 0000000..b69ba43 --- /dev/null +++ b/test/junit/com/jogamp/common/util/LongIntHashMapTest.java @@ -0,0 +1,139 @@ +/** + * Created on Sunday, March 28 2010 21:01 + */ +package com.jogamp.common.util; + +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.Random; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; +import static java.lang.System.*; + +/** + * + * @author Michael Bien + */ +public class LongIntHashMapTest { + + private static int iterations; + private static long[] rndKeys; + private static int[] rndValues; + + @BeforeClass + public static void init() { + + iterations = 20000; + final int keySeed = 42; + final int valueSeed = 23; + + Random keyRnd = new Random(/*keySeed*/); + Random valueRnd = new Random(/*valueSeed*/); + + rndKeys = new long[iterations]; + rndValues = new int[iterations]; + for (int i = 0; i < iterations; i++) { + rndValues[i] = valueRnd.nextInt(); + rndKeys[i] = keyRnd.nextLong(); + } + + } + /** + * Test of put method, of class LongIntHashMap. + */ + @Test + public void testPutRemove() { + + final LongIntHashMap intmap = new LongIntHashMap(); + final HashMap map = new HashMap(); + + // put + for (int i = 0; i < iterations; i++) { + intmap.put(rndKeys[i], rndValues[i]); + + assertTrue(intmap.containsValue(rndValues[i])); + assertTrue(intmap.containsKey(rndKeys[i])); + } + + for (int i = 0; i < iterations; i++) { + map.put(rndKeys[i], rndValues[i]); + } + + assertEquals(map.size(), intmap.size()); + + for (Entry entry : map.entrySet()) { + assertTrue(intmap.containsKey(entry.getKey())); + assertTrue(intmap.containsValue(entry.getValue())); + } + + int i = 0; + for (Entry entry : map.entrySet()) { + assertEquals((int)entry.getValue(), intmap.remove(entry.getKey())); + assertEquals(map.size() - i - 1, intmap.size()); + i++; + } + + } + + @Test + public void benchmark() { + + // simple benchmark + final LongIntHashMap intmap = new LongIntHashMap(1024); + final HashMap map = new HashMap(1024); + + out.println("put"); + long time = currentTimeMillis(); + for (int i = 0; i < iterations; i++) { + intmap.put(rndKeys[i], rndValues[i]); + } + long intmapTime = (currentTimeMillis() - time); + out.println(" iimap: " + intmapTime+"ms"); + + + time = currentTimeMillis(); + for (int i = 0; i < iterations; i++) { + map.put(rndKeys[i], rndValues[i]); + } + long mapTime = (currentTimeMillis() - time); + out.println(" map: " + mapTime+"ms"); + + assertTrue(intmapTime <= mapTime); + + + System.out.println(); + System.out.println("get"); + intmapTime = (currentTimeMillis() - time); + out.println(" iimap: " + intmapTime+"ms"); + for (int i = 0; i < iterations; i++) { + intmap.get(rndValues[i]); + } + + mapTime = (currentTimeMillis() - time); + out.println(" map: " + mapTime+"ms"); + for (int i = 0; i < iterations; i++) { + map.get(rndValues[i]); + } + assertTrue(intmapTime <= mapTime); + + + out.println(); + out.println("remove"); + intmapTime = (currentTimeMillis() - time); + out.println(" iimap: " + intmapTime+"ms"); + for (int i = 0; i < iterations; i++) { + intmap.remove(rndValues[i]); + } + + mapTime = (currentTimeMillis() - time); + out.println(" map: " + mapTime+"ms"); + for (int i = 0; i < iterations; i++) { + map.remove(rndValues[i]); + } + + assertTrue(intmapTime <= mapTime); + } + + +} -- cgit v1.2.3 From afb45360514377a193009d436957898cc5f1855d Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Mon, 12 Apr 2010 23:04:49 +0200 Subject: added Simon Goller to @author list in LongIntHashMap und LongIntHashMapTest. --- src/java/com/jogamp/common/util/LongIntHashMap.java | 3 +++ test/junit/com/jogamp/common/util/LongIntHashMapTest.java | 1 + 2 files changed, 4 insertions(+) (limited to 'test/junit') diff --git a/src/java/com/jogamp/common/util/LongIntHashMap.java b/src/java/com/jogamp/common/util/LongIntHashMap.java index ed8f27b..e17155d 100644 --- a/src/java/com/jogamp/common/util/LongIntHashMap.java +++ b/src/java/com/jogamp/common/util/LongIntHashMap.java @@ -35,8 +35,11 @@ package com.jogamp.common.util; * Original code is based on the skorpios project * released under new BSD license. * @author Michael Bien + * @author Simon Goller * @see IntObjectHashMap * @see IntLongHashMap + * @see LongObjectHashMap + * @see LongLongHashMap */ public class /*name*/LongIntHashMap/*name*/ { diff --git a/test/junit/com/jogamp/common/util/LongIntHashMapTest.java b/test/junit/com/jogamp/common/util/LongIntHashMapTest.java index b69ba43..67a610f 100644 --- a/test/junit/com/jogamp/common/util/LongIntHashMapTest.java +++ b/test/junit/com/jogamp/common/util/LongIntHashMapTest.java @@ -14,6 +14,7 @@ import static java.lang.System.*; /** * * @author Michael Bien + * @author Simon Goller */ public class LongIntHashMapTest { -- cgit v1.2.3