From 4c808ec572808a221d0ce08785dad2d18f77ea5f Mon Sep 17 00:00:00 2001 From: "Elijah C. Menifee" Date: Mon, 23 Aug 2010 03:02:43 +0800 Subject: Fixed benchmarking bugs in primitive HashMap test. Both IntIntHashMapTest and LongIntHashMapTest failed to reset test start time. The time values for intmapGetTime,mapGetTime,intmapRemoveTime,and mapRemoveTime all used the start time value from mapPutTime. This caused the following to be always/guarenteed to be true: mapPutTime < intmapGetTime < mapGetTime < intmapRemoveTime < mapRemoveTime thus not actually testing the following asserts: assertTrue("'get' too slow", intmapGetTime <= mapGetTime); assertTrue("'remove' too slow", intmapRemoveTime <= mapRemoveTime); In addition the results of the test were being printed before the actual test ran. Changed code to reset time to System.nanoTime() prior to each for loop, and moved time calculation and result output to below the test for loop. I also improved the output of the test info, by including the warmup status on benchmark start. --- .../com/jogamp/common/util/IntIntHashMapTest.java | 26 +++++++++++++--------- .../com/jogamp/common/util/LongIntHashMapTest.java | 23 +++++++++++-------- 2 files changed, 29 insertions(+), 20 deletions(-) (limited to 'src/junit/com/jogamp') diff --git a/src/junit/com/jogamp/common/util/IntIntHashMapTest.java b/src/junit/com/jogamp/common/util/IntIntHashMapTest.java index 54f3399..cf3fd20 100644 --- a/src/junit/com/jogamp/common/util/IntIntHashMapTest.java +++ b/src/junit/com/jogamp/common/util/IntIntHashMapTest.java @@ -143,7 +143,8 @@ public class IntIntHashMapTest { final IntIntHashMap intmap = new IntIntHashMap(1024); final HashMap map = new HashMap(1024); - out.println(intmap.getClass().getName()+" vs "+map.getClass().getName()); + out.println(intmap.getClass().getName()+" vs "+map.getClass().getName()+ + " warmup: " + warmup); out.println("put"); long time = nanoTime(); @@ -153,7 +154,6 @@ public class IntIntHashMapTest { long intmapPutTime = (nanoTime() - time); out.println(" iimap: " + intmapPutTime/1000000.0f+"ms"); - time = nanoTime(); for (int i = 0; i < iterations; i++) { map.put(rndKeys[i], rndValues[i]); @@ -164,32 +164,36 @@ public class IntIntHashMapTest { System.out.println(); System.out.println("get"); - long intmapGetTime = (nanoTime() - time); - out.println(" iimap: " + intmapGetTime/1000000.0f+"ms"); + time = nanoTime(); for (int i = 0; i < iterations; i++) { intmap.get(rndValues[i]); } - - long mapGetTime = (nanoTime() - time); - out.println(" map: " + mapGetTime/1000000.0f+"ms"); + long intmapGetTime = (nanoTime() - time); + out.println(" iimap: " + intmapGetTime/1000000.0f+"ms"); + + time = nanoTime(); for (int i = 0; i < iterations; i++) { map.get(rndValues[i]); } + long mapGetTime = (nanoTime() - time); + out.println(" map: " + mapGetTime/1000000.0f+"ms"); out.println(); out.println("remove"); - long intmapRemoveTime = (nanoTime() - time); - out.println(" iimap: " + intmapRemoveTime/1000000.0f+"ms"); + time = nanoTime(); for (int i = 0; i < iterations; i++) { intmap.remove(rndValues[i]); } + long intmapRemoveTime = (nanoTime() - time); + out.println(" iimap: " + intmapRemoveTime/1000000.0f+"ms"); - long mapRemoveTime = (nanoTime() - time); - out.println(" map: " + mapRemoveTime/1000000.0f+"ms"); + time = nanoTime(); for (int i = 0; i < iterations; i++) { map.remove(rndValues[i]); } + long mapRemoveTime = (nanoTime() - time); + out.println(" map: " + mapRemoveTime/1000000.0f+"ms"); if(!warmup) { assertTrue("'put' too slow", intmapPutTime <= mapPutTime); diff --git a/src/junit/com/jogamp/common/util/LongIntHashMapTest.java b/src/junit/com/jogamp/common/util/LongIntHashMapTest.java index 56ed7fd..0670380 100644 --- a/src/junit/com/jogamp/common/util/LongIntHashMapTest.java +++ b/src/junit/com/jogamp/common/util/LongIntHashMapTest.java @@ -143,7 +143,8 @@ public class LongIntHashMapTest { final LongIntHashMap intmap = new LongIntHashMap(1024); final HashMap map = new HashMap(1024); - out.println(intmap.getClass().getName()+" vs "+map.getClass().getName()); + out.println(intmap.getClass().getName()+" vs "+map.getClass().getName()+ + " warmup: " + warmup); out.println("put"); long time = nanoTime(); @@ -164,32 +165,36 @@ public class LongIntHashMapTest { System.out.println(); System.out.println("get"); - long intmapGetTime = (nanoTime() - time); - out.println(" iimap: " + intmapGetTime/1000000.0f+"ms"); + time = nanoTime(); for (int i = 0; i < iterations; i++) { intmap.get(rndValues[i]); } + long intmapGetTime = (nanoTime() - time); + out.println(" iimap: " + intmapGetTime/1000000.0f+"ms"); - long mapGetTime = (nanoTime() - time); - out.println(" map: " + mapGetTime/1000000.0f+"ms"); + time = nanoTime(); for (int i = 0; i < iterations; i++) { map.get(rndValues[i]); } + long mapGetTime = (nanoTime() - time); + out.println(" map: " + mapGetTime/1000000.0f+"ms"); out.println(); out.println("remove"); - long intmapRemoveTime = (nanoTime() - time); - out.println(" iimap: " + intmapRemoveTime/1000000.0f+"ms"); + time = nanoTime(); for (int i = 0; i < iterations; i++) { intmap.remove(rndValues[i]); } + long intmapRemoveTime = (nanoTime() - time); + out.println(" iimap: " + intmapRemoveTime/1000000.0f+"ms"); - long mapRemoveTime = (nanoTime() - time); - out.println(" map: " + mapRemoveTime/1000000.0f+"ms"); + time = nanoTime(); for (int i = 0; i < iterations; i++) { map.remove(rndValues[i]); } + long mapRemoveTime = (nanoTime() - time); + out.println(" map: " + mapRemoveTime/1000000.0f+"ms"); if(!warmup) { assertTrue("'put' too slow", intmapPutTime <= mapPutTime); -- cgit v1.2.3