diff options
author | Sven Gothel <[email protected]> | 2023-03-07 01:16:30 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-03-07 01:16:30 +0100 |
commit | 6545ab42048dfda5f6cb72ce272a331078cd200e (patch) | |
tree | 920b02fb4b62df0c4780c6f685ba9ae07b6bc192 /src/junit | |
parent | 1842451b0e49ac1899ed3ab3515021a6077aff92 (diff) |
Clock: Use Clock.currentNanos() instead of System.nanoTime()
Diffstat (limited to 'src/junit')
3 files changed, 34 insertions, 26 deletions
diff --git a/src/junit/com/jogamp/common/util/IntIntHashMapTest.java b/src/junit/com/jogamp/common/util/IntIntHashMapTest.java index dc523f0..647e471 100644 --- a/src/junit/com/jogamp/common/util/IntIntHashMapTest.java +++ b/src/junit/com/jogamp/common/util/IntIntHashMapTest.java @@ -39,6 +39,7 @@ import java.util.Map.Entry; import org.junit.BeforeClass; import org.junit.Test; +import com.jogamp.common.os.Clock; import com.jogamp.common.os.Platform; import com.jogamp.junit.util.SingletonJunitCase; @@ -254,54 +255,54 @@ public class IntIntHashMapTest extends SingletonJunitCase { " warmup: " + warmup); out.println("put"); - long time = nanoTime(); + long time = Clock.currentNanos(); for (int i = 0; i < iterations; i++) { intmap.put(pairs.keys[i], pairs.values[i]); } - final long intmapPutTime = (nanoTime() - time); + final long intmapPutTime = (Clock.currentNanos() - time); out.println(" iimap: " + intmapPutTime/1000000.0f+"ms"); - time = nanoTime(); + time = Clock.currentNanos(); for (int i = 0; i < iterations; i++) { map.put(pairs.keys[i], pairs.values[i]); } - final long mapPutTime = (nanoTime() - time); + final long mapPutTime = (Clock.currentNanos() - time); out.println(" map: " + mapPutTime/1000000.0f+"ms"); System.out.println(); System.out.println("get"); - time = nanoTime(); + time = Clock.currentNanos(); for (int i = 0; i < iterations; i++) { intmap.get(pairs.keys[i]); } - final long intmapGetTime = (nanoTime() - time); + final long intmapGetTime = (Clock.currentNanos() - time); out.println(" iimap: " + intmapGetTime/1000000.0f+"ms"); - time = nanoTime(); + time = Clock.currentNanos(); for (int i = 0; i < iterations; i++) { map.get(pairs.keys[i]); } - final long mapGetTime = (nanoTime() - time); + final long mapGetTime = (Clock.currentNanos() - time); out.println(" map: " + mapGetTime/1000000.0f+"ms"); out.println(); out.println("remove"); - time = nanoTime(); + time = Clock.currentNanos(); for (int i = 0; i < iterations; i++) { intmap.remove(pairs.keys[i]); } assertEquals(0, intmap.size()); - final long intmapRemoveTime = (nanoTime() - time); + final long intmapRemoveTime = (Clock.currentNanos() - time); out.println(" iimap: " + intmapRemoveTime/1000000.0f+"ms"); - time = nanoTime(); + time = Clock.currentNanos(); for (int i = 0; i < iterations; i++) { map.remove(pairs.keys[i]); } assertEquals(0, map.size()); - final long mapRemoveTime = (nanoTime() - time); + final long mapRemoveTime = (Clock.currentNanos() - time); out.println(" map: " + mapRemoveTime/1000000.0f+"ms"); if(!warmup) { diff --git a/src/junit/com/jogamp/common/util/LongIntHashMapTest.java b/src/junit/com/jogamp/common/util/LongIntHashMapTest.java index 9ea4206..60f404d 100644 --- a/src/junit/com/jogamp/common/util/LongIntHashMapTest.java +++ b/src/junit/com/jogamp/common/util/LongIntHashMapTest.java @@ -39,6 +39,7 @@ import java.util.Map.Entry; import org.junit.BeforeClass; import org.junit.Test; +import com.jogamp.common.os.Clock; import com.jogamp.common.os.Platform; import com.jogamp.junit.util.SingletonJunitCase; @@ -143,55 +144,55 @@ public class LongIntHashMapTest extends SingletonJunitCase { " warmup: " + warmup); out.println("put"); - long time = nanoTime(); + long time = Clock.currentNanos(); for (int i = 0; i < iterations; i++) { intmap.put(pairs.keys[i], pairs.values[i]); } - final long intmapPutTime = (nanoTime() - time); + final long intmapPutTime = (Clock.currentNanos() - time); out.println(" iimap: " + intmapPutTime/1000000.0f+"ms"); - time = nanoTime(); + time = Clock.currentNanos(); for (int i = 0; i < iterations; i++) { map.put(pairs.keys[i], pairs.values[i]); } - final long mapPutTime = (nanoTime() - time); + final long mapPutTime = (Clock.currentNanos() - time); out.println(" map: " + mapPutTime/1000000.0f+"ms"); System.out.println(); System.out.println("get"); - time = nanoTime(); + time = Clock.currentNanos(); for (int i = 0; i < iterations; i++) { intmap.get(pairs.keys[i]); } - final long intmapGetTime = (nanoTime() - time); + final long intmapGetTime = (Clock.currentNanos() - time); out.println(" iimap: " + intmapGetTime/1000000.0f+"ms"); - time = nanoTime(); + time = Clock.currentNanos(); for (int i = 0; i < iterations; i++) { map.get(pairs.keys[i]); } - final long mapGetTime = (nanoTime() - time); + final long mapGetTime = (Clock.currentNanos() - time); out.println(" map: " + mapGetTime/1000000.0f+"ms"); out.println(); out.println("remove"); - time = nanoTime(); + time = Clock.currentNanos(); for (int i = 0; i < iterations; i++) { intmap.remove(pairs.keys[i]); } assertEquals(0, intmap.size()); - final long intmapRemoveTime = (nanoTime() - time); + final long intmapRemoveTime = (Clock.currentNanos() - time); out.println(" iimap: " + intmapRemoveTime/1000000.0f+"ms"); - time = nanoTime(); + time = Clock.currentNanos(); for (int i = 0; i < iterations; i++) { map.remove(pairs.keys[i]); } assertEquals(0, map.size()); - final long mapRemoveTime = (nanoTime() - time); + final long mapRemoveTime = (Clock.currentNanos() - time); out.println(" map: " + mapRemoveTime/1000000.0f+"ms"); if(!warmup) { diff --git a/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java b/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java index e5456f4..e119569 100644 --- a/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java +++ b/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java @@ -37,6 +37,7 @@ import java.util.Map; import org.junit.Assert; import org.junit.Test; +import com.jogamp.common.os.Clock; import com.jogamp.common.os.Platform; import com.jogamp.common.util.InterruptSource; import com.jogamp.junit.util.SingletonJunitCase; @@ -141,6 +142,7 @@ public class TestRecursiveLock01 extends SingletonJunitCase { incrDeferredThreadCount(); } + @Override public void run() { if(DEBUG) { System.err.print("[a2"); @@ -175,9 +177,9 @@ public class TestRecursiveLock01 extends SingletonJunitCase { } public final void lock() { - long td = System.nanoTime(); + long td = Clock.currentNanos(); locker.lock(); - td = System.nanoTime() - td; + td = Clock.currentNanos() - td; final String cur = Thread.currentThread().getName(); ThreadStat ts = threadWaitMap.get(cur); @@ -258,14 +260,17 @@ public class TestRecursiveLock01 extends SingletonJunitCase { this.yieldMode = yieldMode; } + @Override public final void stop() { shouldStop = true; } + @Override public final boolean isStopped() { return stopped; } + @Override public void waitUntilStopped() { synchronized(this) { while(!stopped) { @@ -279,6 +284,7 @@ public class TestRecursiveLock01 extends SingletonJunitCase { } + @Override public void run() { synchronized(this) { while(!shouldStop && loops>0) { |