--- jsr166/src/test/loops/IteratorLoops.java 2005/11/29 08:58:22 1.2 +++ jsr166/src/test/loops/IteratorLoops.java 2009/11/03 01:04:02 1.7 @@ -17,26 +17,34 @@ import java.util.*; public final class IteratorLoops { static final int DEFAULT_SIZE = 16384; - static final int DEFAULT_TRIALS = 2; + static final int DEFAULT_TRIALS = 4; static final int NC = 16; // number of collections must be power of 2 static volatile long mismatches = 0; static int randomSeed = 3122688; public static void main(String[] args) throws Exception { Class klass = Class.forName(args[0]); - int n = (args.length <= 1)? DEFAULT_SIZE : Integer.parseInt(args[1]); - int t = (args.length <= 2)? DEFAULT_TRIALS : Integer.parseInt(args[2]); + int n = (args.length <= 1) ? DEFAULT_SIZE : Integer.parseInt(args[1]); + int t = (args.length <= 2) ? DEFAULT_TRIALS : Integer.parseInt(args[2]); System.out.print("Class: " + klass.getName()); - System.out.print(" ~iters: " + (long)n * (long)n); + System.out.print(" ~iters: " + (long) n * (long) n); System.out.print(" trials: " + t); System.out.println(); Collection[] colls = (Collection[])new Collection[NC]; - for (int k = 0; k < colls.length; ++k) - colls[k] = (Collection)klass.newInstance(); + for (int k = 0; k < colls.length; ++k) { + Object x = klass.newInstance(); + if (x instanceof Collection) + colls[k] = (Collection) x; + else if (x instanceof Map) + colls[k] = (Collection) + Collections.newSetFromMap((Map) x); + else + throw new Error("bad class"); + } for (int i = 0; i < t; ++i) new IteratorLoops(colls).oneRun(n); @@ -57,7 +65,7 @@ public final class IteratorLoops { preload(n); long startTime = System.nanoTime(); long count = traversals(n); - double elapsed = (double)(System.nanoTime() - startTime); + double elapsed = (double) (System.nanoTime() - startTime); double npi = elapsed / count; double secs = elapsed / 1000000000; System.out.printf("%7.1f ns/iter %8.3fs run time\n", npi, secs); @@ -112,7 +120,8 @@ public final class IteratorLoops { k >>>= 1; } // let GC settle down - try { Thread.sleep(500); } catch(Exception ex) { return; } + try { Thread.sleep(500); } + catch (Exception ex) { return; } }