--- jsr166/src/test/loops/IntMapCheck.java 2009/10/23 19:57:06 1.3 +++ jsr166/src/test/loops/IntMapCheck.java 2009/10/29 23:09:07 1.4 @@ -35,10 +35,10 @@ public class IntMapCheck { } - if (args.length > 1) + if (args.length > 1) numTests = Integer.parseInt(args[1]); - if (args.length > 2) + if (args.length > 2) size = Integer.parseInt(args[2]); boolean doSerializeTest = args.length > 3; @@ -49,13 +49,13 @@ public class IntMapCheck { while (absentSize < size) absentSize <<= 1; absentMask = absentSize-1; absent = new Integer[absentSize]; - for (int i = 0; i < absentSize/2; ++i) + for (int i = 0; i < absentSize/2; ++i) absent[i] = Integer.valueOf(-i - 1); - for (int i = absentSize/2; i < absentSize; ++i) + for (int i = absentSize/2; i < absentSize; ++i) absent[i] = Integer.valueOf(size + i + 1); Integer[] key = new Integer[size]; - for (int i = 0; i < size; ++i) + for (int i = 0; i < size; ++i) key[i] = Integer.valueOf(i); for (int rep = 0; rep < numTests; ++rep) { @@ -98,7 +98,7 @@ public class IntMapCheck { if (s.get(key[i]) != null) ++sum; } } - timer.finish(); + timer.finish(); reallyAssert (sum == expect * iters); } @@ -111,7 +111,7 @@ public class IntMapCheck { if ((Integer)(s.get(i)) != i) ++sum; } } - timer.finish(); + timer.finish(); reallyAssert (sum == expect * iters); } @@ -122,7 +122,7 @@ public class IntMapCheck { for (int i = 0; i < n; i++) { if (s.remove(key[i]) != null) ++sum; } - timer.finish(); + timer.finish(); reallyAssert (sum == expect); } @@ -134,7 +134,7 @@ public class IntMapCheck { Integer v = absent[i & absentMask]; if (s.put(k, v) == null) ++sum; } - timer.finish(); + timer.finish(); reallyAssert (sum == expect); } @@ -144,7 +144,7 @@ public class IntMapCheck { for (int i = 0; i < n; i++) { if (s.containsKey(key[i])) ++sum; } - timer.finish(); + timer.finish(); reallyAssert (sum == expect); } @@ -154,7 +154,7 @@ public class IntMapCheck { for (int i = n-2; i >= 0; i-=2) { if (s.remove(key[i]) != null) ++sum; } - timer.finish(); + timer.finish(); reallyAssert (sum == expect); } @@ -165,7 +165,7 @@ public class IntMapCheck { if (s.get(k1[i]) != null) ++sum; if (s.get(k2[i & absentMask]) != null) ++sum; } - timer.finish(); + timer.finish(); reallyAssert (sum == n); } @@ -176,7 +176,7 @@ public class IntMapCheck { if (s.containsKey(k1[i])) ++sum; if (s.containsKey(k2[i & absentMask])) ++sum; } - timer.finish(); + timer.finish(); reallyAssert (sum == n); } @@ -186,7 +186,7 @@ public class IntMapCheck { for (int i = 0; i < n; i++) { if (s.get(key[i]) != null) ++sum; } - timer.finish(); + timer.finish(); reallyAssert (sum == expect); } @@ -198,7 +198,7 @@ public class IntMapCheck { int step = absentSize / iters; for (int i = 0; i < absentSize; i += step) if (s.containsValue(absent[i])) ++sum; - timer.finish(); + timer.finish(); reallyAssert (sum != 0); } @@ -210,7 +210,7 @@ public class IntMapCheck { for (int i = 0; i < size; i++) { if (ks.contains(key[i])) ++sum; } - timer.finish(); + timer.finish(); reallyAssert (sum == size); } @@ -222,8 +222,8 @@ public class IntMapCheck { if(it.next() != MISSING) ++sum; } - timer.finish(); - // if (sum != size) + timer.finish(); + // if (sum != size) // System.out.println("iters " + sum + " size " + size); reallyAssert (sum == size); } @@ -235,8 +235,8 @@ public class IntMapCheck { if(it.next() != MISSING) ++sum; } - timer.finish(); - // if (sum != size) + timer.finish(); + // if (sum != size) // System.out.println("iters " + sum + " size " + size); reallyAssert (sum == size); } @@ -247,7 +247,7 @@ public class IntMapCheck { if(it.next() != MISSING) ++sum; } - timer.finish(); + timer.finish(); reallyAssert (sum == size); } @@ -256,7 +256,7 @@ public class IntMapCheck { reallyAssert (s.size() == size); int sum = 0; timer.start("Iter XEntry ", size); - Iterator it = s.entrySet().iterator(); + Iterator it = s.entrySet().iterator(); Integer k = null; Integer v = null; for (int i = 0; i < size-pos; ++i) { @@ -281,7 +281,7 @@ public class IntMapCheck { reallyAssert (s.size() == size-1); s.put(k, v); reallyAssert (seen.size() == size); - timer.finish(); + timer.finish(); reallyAssert (sum == size); reallyAssert (s.size() == size); } @@ -293,7 +293,7 @@ public class IntMapCheck { ittest2(s, size); ittest3(s, size); } - // for (int i = 0; i < size-1; ++i) + // for (int i = 0; i < size-1; ++i) // ittest4(s, size, i); } @@ -305,7 +305,7 @@ public class IntMapCheck { if (en.nextElement() != MISSING) ++sum; } - timer.finish(); + timer.finish(); reallyAssert (sum == size); } @@ -316,7 +316,7 @@ public class IntMapCheck { if (en.nextElement() != MISSING) ++sum; } - timer.finish(); + timer.finish(); reallyAssert (sum == size); } @@ -325,24 +325,24 @@ public class IntMapCheck { int sum = 0; timer.start("Iterf Enumeration Key ", size); - Enumeration en = ht.keys(); + Enumeration en = ht.keys(); for (int i = 0; i < size; ++i) { if (en.nextElement() != MISSING) ++sum; } - timer.finish(); + timer.finish(); reallyAssert (sum == size); } static void entest4(Hashtable ht, int size) { int sum = 0; timer.start("Iterf Enumeration Value", size); - Enumeration en = ht.elements(); + Enumeration en = ht.elements(); for (int i = 0; i < size; ++i) { if (en.nextElement() != MISSING) ++sum; } - timer.finish(); + timer.finish(); reallyAssert (sum == size); } @@ -367,14 +367,14 @@ public class IntMapCheck { it.remove(); } reallyAssert(s.isEmpty()); - timer.finish(); + timer.finish(); } static void stest(Map s, int size) throws Exception { - if (!(s instanceof Serializable)) + if (!(s instanceof Serializable)) return; System.out.print("Serialize : "); - + for (int i = 0; i < size; i++) { s.put(Integer.valueOf(i), Integer.valueOf(1)); } @@ -399,7 +399,7 @@ public class IntMapCheck { reallyAssert (s.equals(m)); } - + static void test(Map s, Integer[] key) { int size = key.length; @@ -433,7 +433,7 @@ public class IntMapCheck { reallyAssert(s.size() == size); timer.start("Clear ", size); s.clear(); - timer.finish(); + timer.finish(); t1("Get (absent) ", size, s, key, 0, 1); t4("ContainsKey ", size, s, key, 0); t2("Remove (absent) ", size, s, key, 0); @@ -445,7 +445,7 @@ public class IntMapCheck { reallyAssert(s.size() == 0); timer.start("Clear ", size); s.clear(); - timer.finish(); + timer.finish(); t3("Put (presized) ", size, s, key, size); timer.start("Put (putAll) ", size * 2); @@ -455,22 +455,22 @@ public class IntMapCheck { s2.putAll(s); } catch (Exception e) { e.printStackTrace(); return; } - timer.finish(); - + timer.finish(); + timer.start("Iter Equals ", size * 2); boolean eqt = s2.equals(s) && s.equals(s2); reallyAssert (eqt); - timer.finish(); + timer.finish(); timer.start("Iter HashCode ", size * 2); int shc = s.hashCode(); int s2hc = s2.hashCode(); reallyAssert (shc == s2hc); - timer.finish(); + timer.finish(); timer.start("Put (present) ", size * 2); s2.putAll(s); - timer.finish(); + timer.finish(); timer.start("Put (present) ", size); int ipsum = 0; @@ -480,7 +480,7 @@ public class IntMapCheck { ++ipsum; } reallyAssert (ipsum == s.size()); - timer.finish(); + timer.finish(); timer.start("Iter EntrySet contains ", size * 2); Set es2 = s2.entrySet(); @@ -489,7 +489,7 @@ public class IntMapCheck { Object entry = i1.next(); if (es2.contains(entry)) ++sum; } - timer.finish(); + timer.finish(); reallyAssert (sum == size); Integer hold = s2.get(key[size-1]); @@ -497,13 +497,13 @@ public class IntMapCheck { timer.start("Iter Equals ", size * 2); eqt = s2.equals(s) && s.equals(s2); reallyAssert (!eqt); - timer.finish(); + timer.finish(); timer.start("Iter HashCode ", size * 2); int s1h = s.hashCode(); int s2h = s2.hashCode(); reallyAssert (s1h != s2h); - timer.finish(); + timer.finish(); s2.put(key[size-1], hold); timer.start("Remove (present) ", size * 2); @@ -511,13 +511,13 @@ public class IntMapCheck { Set es = s.entrySet(); while (s2i.hasNext()) reallyAssert(es.remove(s2i.next())); - timer.finish(); + timer.finish(); reallyAssert (s.isEmpty()); timer.start("Clear ", size); s2.clear(); - timer.finish(); + timer.finish(); reallyAssert (s2.isEmpty() && s.isEmpty()); } @@ -528,14 +528,14 @@ public class IntMapCheck { private String cname; static final java.util.TreeMap accum = new java.util.TreeMap(); - + static void printStats() { for (Iterator it = accum.entrySet().iterator(); it.hasNext(); ) { Map.Entry e = (Map.Entry)(it.next()); Stats stats = ((Stats)(e.getValue())); long n = stats.number; double t; - if (n > 0) + if (n > 0) t = stats.sum / n; else t = stats.least; @@ -543,14 +543,14 @@ public class IntMapCheck { System.out.println(e.getKey() + ": " + nano); } } - + void start(String name, long numOps) { this.name = name; this.cname = classify(); this.numOps = numOps; startTime = System.nanoTime(); } - + String classify() { if (name.startsWith("Get")) @@ -561,7 +561,7 @@ public class IntMapCheck { return "Remove "; else if (name.startsWith("Iter")) return "Iter "; - else + else return null; } @@ -616,4 +616,3 @@ public class IntMapCheck { } } -