ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/CollectionLoops.java
(Generate patch)

Comparing jsr166/src/test/loops/CollectionLoops.java (file contents):
Revision 1.4 by jsr166, Mon Nov 2 23:42:46 2009 UTC vs.
Revision 1.12 by jsr166, Sat Dec 31 19:18:26 2016 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 <
8 < import java.util.*;
9 < import java.util.concurrent.*;
7 > import java.util.Collection;
8 > import java.util.Random;
9 > import java.util.concurrent.CyclicBarrier;
10 > import java.util.concurrent.ExecutorService;
11 > import java.util.concurrent.Executors;
12  
13   public class CollectionLoops {
14      static int pinsert     = 100;
# Line 23 | Line 25 | public class CollectionLoops {
25          int nkeys       = 10000;
26          int nops        = 100000;
27  
28 <        Class collectionClass = null;
28 >        Class<?> collectionClass = null;
29          if (args.length > 0) {
30              try {
31                  collectionClass = Class.forName(args[0]);
# Line 65 | Line 67 | public class CollectionLoops {
67          test(4, 100, 100, collectionClass);
68          print = true;
69  
68        int k = 1;
70          int warmups = 2;
71 <        for (int i = 1; i <= maxThreads;) {
71 >        for (int k = 1, i = 1; i <= maxThreads;) {
72              Thread.sleep(100);
73              test(i, nkeys, nops, collectionClass);
74              if (warmups > 0)
# Line 104 | Line 105 | public class CollectionLoops {
105          }
106      }
107  
108 <    static void test(int i, int nk, int nops, Class collectionClass) throws Exception {
108 >    static void test(int i, int nk, int nops, Class<?> collectionClass) throws Exception {
109          if (print)
110              System.out.print("Threads: " + i + "\t:");
111 <        Collection<Integer> collection = (Collection<Integer>)collectionClass.newInstance();
111 >        Collection<Integer> collection =
112 >            (Collection<Integer>) collectionClass.getConstructor().newInstance();
113          Integer[] key = makeKeys(nk);
114          // Uncomment to start with a non-empty table
115          for (int j = 0; j < nk; j += 2)
# Line 120 | Line 122 | public class CollectionLoops {
122          barrier.await();
123          barrier.await();
124          long time = timer.getTime();
125 <        long tpo = time / (i * (long)nops);
125 >        long tpo = time / (i * (long) nops);
126          if (print)
127              System.out.print(LoopHelpers.rightJustify(tpo) + " ns per op");
128 <        double secs = (double)(time) / 1000000000.0;
128 >        double secs = (double) time / 1000000000.0;
129          if (print)
130              System.out.print("\t " + secs + "s run time");
131          if (checkSum == 0) System.out.print(" ");
# Line 141 | Line 143 | public class CollectionLoops {
143          int total;
144          int nops;
145  
146 <        Runner(int id, Collection<Integer> collection, Integer[] key,  CyclicBarrier barrier, int nops) {
146 >        Runner(int id, Collection<Integer> collection, Integer[] key, CyclicBarrier barrier, int nops) {
147              this.collection = collection;
148              this.key = key;
149              this.barrier = barrier;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines