--- jsr166/src/test/loops/IntMapCheck.java 2009/11/02 23:51:32 1.6 +++ jsr166/src/test/loops/IntMapCheck.java 2015/01/15 18:34:19 1.14 @@ -1,14 +1,14 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ */ /** * @test * @synopsis Times and checks basic map operations */ -import java.util.*; import java.io.*; +import java.util.*; public class IntMapCheck { static int absentSize; @@ -22,7 +22,7 @@ public class IntMapCheck { } public static void main(String[] args) throws Exception { - Class mapClass = java.util.concurrent.ConcurrentHashMap.class; + Class mapClass = java.util.concurrent.ConcurrentHashMap.class; int numTests = 50; int size = 75000; @@ -34,7 +34,6 @@ public class IntMapCheck { } } - if (args.length > 1) numTests = Integer.parseInt(args[1]); @@ -68,12 +67,11 @@ public class IntMapCheck { TestTimer.printStats(); - if (doSerializeTest) stest(newMap(mapClass), size); } - static Map newMap(Class cl) { + static Map newMap(Class cl) { try { Map m = (Map)cl.newInstance(); return m; @@ -82,7 +80,6 @@ public class IntMapCheck { } } - static void runTest(Map s, Integer[] key) { int size = key.length; long startTime = System.nanoTime(); @@ -99,7 +96,7 @@ public class IntMapCheck { } } timer.finish(); - reallyAssert (sum == expect * iters); + reallyAssert(sum == expect * iters); } static void t1Boxed(String nm, int n, Map s, Integer[] key, int expect) { @@ -108,14 +105,13 @@ public class IntMapCheck { timer.start(nm, n * iters); for (int j = 0; j < iters; ++j) { for (int i = 0; i < n; i++) { - if ((Integer) (s.get(i)) != i) ++sum; + if (s.get(i) != i) ++sum; } } timer.finish(); - reallyAssert (sum == expect * iters); + reallyAssert(sum == expect * iters); } - static void t2(String nm, int n, Map s, Integer[] key, int expect) { int sum = 0; timer.start(nm, n); @@ -123,7 +119,7 @@ public class IntMapCheck { if (s.remove(key[i]) != null) ++sum; } timer.finish(); - reallyAssert (sum == expect); + reallyAssert(sum == expect); } static void t3(String nm, int n, Map s, Integer[] key, int expect) { @@ -135,7 +131,7 @@ public class IntMapCheck { if (s.put(k, v) == null) ++sum; } timer.finish(); - reallyAssert (sum == expect); + reallyAssert(sum == expect); } static void t4(String nm, int n, Map s, Integer[] key, int expect) { @@ -145,7 +141,7 @@ public class IntMapCheck { if (s.containsKey(key[i])) ++sum; } timer.finish(); - reallyAssert (sum == expect); + reallyAssert(sum == expect); } static void t5(String nm, int n, Map s, Integer[] key, int expect) { @@ -155,7 +151,7 @@ public class IntMapCheck { if (s.remove(key[i]) != null) ++sum; } timer.finish(); - reallyAssert (sum == expect); + reallyAssert(sum == expect); } static void t6(String nm, int n, Map s, Integer[] k1, Integer[] k2) { @@ -166,7 +162,7 @@ public class IntMapCheck { if (s.get(k2[i & absentMask]) != null) ++sum; } timer.finish(); - reallyAssert (sum == n); + reallyAssert(sum == n); } static void t7(String nm, int n, Map s, Integer[] k1, Integer[] k2) { @@ -177,7 +173,7 @@ public class IntMapCheck { if (s.containsKey(k2[i & absentMask])) ++sum; } timer.finish(); - reallyAssert (sum == n); + reallyAssert(sum == n); } static void t8(String nm, int n, Map s, Integer[] key, int expect) { @@ -187,10 +183,9 @@ public class IntMapCheck { if (s.get(key[i]) != null) ++sum; } timer.finish(); - reallyAssert (sum == expect); + reallyAssert(sum == expect); } - static void t9(Map s) { int sum = 0; int iters = 20; @@ -199,10 +194,9 @@ public class IntMapCheck { for (int i = 0; i < absentSize; i += step) if (s.containsValue(absent[i])) ++sum; timer.finish(); - reallyAssert (sum != 0); + reallyAssert(sum != 0); } - static void ktest(Map s, int size, Integer[] key) { timer.start("ContainsKey ", size); Set ks = s.keySet(); @@ -211,10 +205,9 @@ public class IntMapCheck { if (ks.contains(key[i])) ++sum; } timer.finish(); - reallyAssert (sum == size); + reallyAssert(sum == size); } - static void ittest1(Map s, int size) { int sum = 0; timer.start("Iter Key ", size); @@ -225,7 +218,7 @@ public class IntMapCheck { timer.finish(); // if (sum != size) // System.out.println("iters " + sum + " size " + size); - reallyAssert (sum == size); + reallyAssert(sum == size); } static void ittest2(Map s, int size) { @@ -238,7 +231,7 @@ public class IntMapCheck { timer.finish(); // if (sum != size) // System.out.println("iters " + sum + " size " + size); - reallyAssert (sum == size); + reallyAssert(sum == size); } static void ittest3(Map s, int size) { int sum = 0; @@ -248,12 +241,12 @@ public class IntMapCheck { ++sum; } timer.finish(); - reallyAssert (sum == size); + reallyAssert(sum == size); } static void ittest4(Map s, int size, int pos) { IdentityHashMap seen = new IdentityHashMap(size); - reallyAssert (s.size() == size); + reallyAssert(s.size() == size); int sum = 0; timer.start("Iter XEntry ", size); Iterator it = s.entrySet().iterator(); @@ -267,26 +260,25 @@ public class IntMapCheck { if (v != MISSING) ++sum; } - reallyAssert (s.containsKey(k)); + reallyAssert(s.containsKey(k)); it.remove(); - reallyAssert (!s.containsKey(k)); + reallyAssert(!s.containsKey(k)); while (it.hasNext()) { Map.Entry x = (Map.Entry)(it.next()); - Integer k2 = (Integer) x.getKey(); + Integer k2 = x.getKey(); seen.put(k2, k2); if (k2 != MISSING) ++sum; } - reallyAssert (s.size() == size-1); + reallyAssert(s.size() == size-1); s.put(k, v); - reallyAssert (seen.size() == size); + reallyAssert(seen.size() == size); timer.finish(); - reallyAssert (sum == size); - reallyAssert (s.size() == size); + reallyAssert(sum == size); + reallyAssert(s.size() == size); } - static void ittest(Map s, int size) { for (int i = 0; i < 4; ++i) { ittest1(s, size); @@ -306,7 +298,7 @@ public class IntMapCheck { ++sum; } timer.finish(); - reallyAssert (sum == size); + reallyAssert(sum == size); } static void entest2(Hashtable ht, int size) { @@ -317,10 +309,9 @@ public class IntMapCheck { ++sum; } timer.finish(); - reallyAssert (sum == size); + reallyAssert(sum == size); } - static void entest3(Hashtable ht, int size) { int sum = 0; @@ -331,7 +322,7 @@ public class IntMapCheck { ++sum; } timer.finish(); - reallyAssert (sum == size); + reallyAssert(sum == size); } static void entest4(Hashtable ht, int size) { @@ -343,7 +334,7 @@ public class IntMapCheck { ++sum; } timer.finish(); - reallyAssert (sum == size); + reallyAssert(sum == size); } static void entest(Map s, int size) { @@ -396,10 +387,9 @@ public class IntMapCheck { System.out.print(time + "ms"); if (s instanceof IdentityHashMap) return; - reallyAssert (s.equals(m)); + reallyAssert(s.equals(m)); } - static void test(Map s, Integer[] key) { int size = key.length; @@ -459,13 +449,13 @@ public class IntMapCheck { timer.start("Iter Equals ", size * 2); boolean eqt = s2.equals(s) && s.equals(s2); - reallyAssert (eqt); + reallyAssert(eqt); timer.finish(); timer.start("Iter HashCode ", size * 2); int shc = s.hashCode(); int s2hc = s2.hashCode(); - reallyAssert (shc == s2hc); + reallyAssert(shc == s2hc); timer.finish(); timer.start("Put (present) ", size * 2); @@ -479,7 +469,7 @@ public class IntMapCheck { if (s2.put(me.getKey(), me.getValue()) != null) ++ipsum; } - reallyAssert (ipsum == s.size()); + reallyAssert(ipsum == s.size()); timer.finish(); timer.start("Iter EntrySet contains ", size * 2); @@ -490,19 +480,19 @@ public class IntMapCheck { if (es2.contains(entry)) ++sum; } timer.finish(); - reallyAssert (sum == size); + reallyAssert(sum == size); Integer hold = s2.get(key[size-1]); s2.put(key[size-1], absent[0]); timer.start("Iter Equals ", size * 2); eqt = s2.equals(s) && s.equals(s2); - reallyAssert (!eqt); + reallyAssert(!eqt); timer.finish(); timer.start("Iter HashCode ", size * 2); int s1h = s.hashCode(); int s2h = s2.hashCode(); - reallyAssert (s1h != s2h); + reallyAssert(s1h != s2h); timer.finish(); s2.put(key[size-1], hold); @@ -513,12 +503,12 @@ public class IntMapCheck { reallyAssert(es.remove(s2i.next())); timer.finish(); - reallyAssert (s.isEmpty()); + reallyAssert(s.isEmpty()); timer.start("Clear ", size); s2.clear(); timer.finish(); - reallyAssert (s2.isEmpty() && s.isEmpty()); + reallyAssert(s2.isEmpty() && s.isEmpty()); } static class TestTimer { @@ -551,7 +541,6 @@ public class IntMapCheck { startTime = System.nanoTime(); } - String classify() { if (name.startsWith("Get")) return "Get "; @@ -568,7 +557,7 @@ public class IntMapCheck { void finish() { long endTime = System.nanoTime(); long time = endTime - startTime; - double timePerOp = ((double)time)/numOps; + double timePerOp = ((double) time)/numOps; Object st = accum.get(name); if (st == null) @@ -607,7 +596,7 @@ public class IntMapCheck { static void shuffle(Integer[] keys) { int size = keys.length; - for (int i=size; i>1; i--) { + for (int i = size; i > 1; i--) { int r = rng.nextInt(i); Integer t = keys[i-1]; keys[i-1] = keys[r];