--- jsr166/src/test/loops/CollectionLoops.java 2009/11/02 23:42:46 1.4 +++ jsr166/src/test/loops/CollectionLoops.java 2016/12/31 19:18:26 1.12 @@ -1,12 +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/ */ - -import java.util.*; -import java.util.concurrent.*; +import java.util.Collection; +import java.util.Random; +import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; public class CollectionLoops { static int pinsert = 100; @@ -23,7 +25,7 @@ public class CollectionLoops { int nkeys = 10000; int nops = 100000; - Class collectionClass = null; + Class collectionClass = null; if (args.length > 0) { try { collectionClass = Class.forName(args[0]); @@ -65,9 +67,8 @@ public class CollectionLoops { test(4, 100, 100, collectionClass); print = true; - int k = 1; int warmups = 2; - for (int i = 1; i <= maxThreads;) { + for (int k = 1, i = 1; i <= maxThreads;) { Thread.sleep(100); test(i, nkeys, nops, collectionClass); if (warmups > 0) @@ -104,10 +105,11 @@ public class CollectionLoops { } } - static void test(int i, int nk, int nops, Class collectionClass) throws Exception { + static void test(int i, int nk, int nops, Class collectionClass) throws Exception { if (print) System.out.print("Threads: " + i + "\t:"); - Collection collection = (Collection)collectionClass.newInstance(); + Collection collection = + (Collection) collectionClass.getConstructor().newInstance(); Integer[] key = makeKeys(nk); // Uncomment to start with a non-empty table for (int j = 0; j < nk; j += 2) @@ -120,10 +122,10 @@ public class CollectionLoops { barrier.await(); barrier.await(); long time = timer.getTime(); - long tpo = time / (i * (long)nops); + long tpo = time / (i * (long) nops); if (print) System.out.print(LoopHelpers.rightJustify(tpo) + " ns per op"); - double secs = (double)(time) / 1000000000.0; + double secs = (double) time / 1000000000.0; if (print) System.out.print("\t " + secs + "s run time"); if (checkSum == 0) System.out.print(" "); @@ -141,7 +143,7 @@ public class CollectionLoops { int total; int nops; - Runner(int id, Collection collection, Integer[] key, CyclicBarrier barrier, int nops) { + Runner(int id, Collection collection, Integer[] key, CyclicBarrier barrier, int nops) { this.collection = collection; this.key = key; this.barrier = barrier;