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.2 by dl, Mon Feb 19 00:46:06 2007 UTC vs.
Revision 1.3 by jsr166, Thu Oct 29 23:09:07 2009 UTC

# Line 32 | Line 32 | public class CollectionLoops {
32              }
33          }
34  
35 <        if (args.length > 1)
35 >        if (args.length > 1)
36              maxThreads = Integer.parseInt(args[1]);
37  
38 <        if (args.length > 2)
38 >        if (args.length > 2)
39              nkeys = Integer.parseInt(args[2]);
40  
41 <        if (args.length > 3)
41 >        if (args.length > 3)
42              pinsert = Integer.parseInt(args[3]);
43  
44 <        if (args.length > 4)
44 >        if (args.length > 4)
45              premove = Integer.parseInt(args[4]);
46  
47 <        if (args.length > 5)
47 >        if (args.length > 5)
48              nops = Integer.parseInt(args[5]);
49  
50          // normalize probabilities wrt random number generator
51          removesPerMaxRandom = (int)(((double)premove/100.0 * 0x7FFFFFFFL));
52          insertsPerMaxRandom = (int)(((double)pinsert/100.0 * 0x7FFFFFFFL));
53 <        
53 >
54          System.out.print("Class: " + collectionClass.getName());
55          System.out.print(" threads: " + maxThreads);
56          System.out.print(" size: " + nkeys);
# Line 75 | Line 75 | public class CollectionLoops {
75              else if (i == k) {
76                  k = i << 1;
77                  i = i + (i >>> 1);
78 <            }
78 >            }
79              else if (i == 1 && k == 2) {
80                  i = k;
81                  warmups = 1;
82              }
83 <            else
83 >            else
84                  i = k;
85          }
86          pool.shutdown();
# Line 89 | Line 89 | public class CollectionLoops {
89      static Integer[] makeKeys(int n) {
90          LoopHelpers.SimpleRandom rng = new LoopHelpers.SimpleRandom();
91          Integer[] key = new Integer[n];
92 <        for (int i = 0; i < key.length; ++i)
92 >        for (int i = 0; i < key.length; ++i)
93              key[i] = new Integer(rng.next());
94          return key;
95      }
# Line 110 | Line 110 | public class CollectionLoops {
110          Collection<Integer> collection = (Collection<Integer>)collectionClass.newInstance();
111          Integer[] key = makeKeys(nk);
112          // Uncomment to start with a non-empty table
113 <        for (int j = 0; j < nk; j += 2)
113 >        for (int j = 0; j < nk; j += 2)
114              collection.add(key[j]);
115          shuffleKeys(key);
116          LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
117          CyclicBarrier barrier = new CyclicBarrier(i+1, timer);
118 <        for (int t = 0; t < i; ++t)
118 >        for (int t = 0; t < i; ++t)
119              pool.execute(new Runner(t, collection, key, barrier, nops));
120          barrier.await();
121          barrier.await();
# Line 142 | Line 142 | public class CollectionLoops {
142          int nops;
143  
144          Runner(int id, Collection<Integer> collection, Integer[] key,  CyclicBarrier barrier, int nops) {
145 <            this.collection = collection;
146 <            this.key = key;
145 >            this.collection = collection;
146 >            this.key = key;
147              this.barrier = barrier;
148              this.nops = nops;
149 <            position = key.length / (id + 1);
149 >            position = key.length / (id + 1);
150              rng = new LoopHelpers.SimpleRandom((id + 1) * 8862213513L);
151              rng.next();
152          }
# Line 160 | Line 160 | public class CollectionLoops {
160                  while (ops > 0) {
161                      int r = rng.next();
162                      p += (r & 7) - 3;
163 <                    while (p >= key.length) p -= key.length;  
163 >                    while (p >= key.length) p -= key.length;
164                      while (p < 0) p += key.length;
165  
166                      Integer k = key[p];
167                      if (c.contains(k)) {
168                          if (r < removesPerMaxRandom) {
169                              if (c.remove(k)) {
170 <                                p = Math.abs(total % key.length);
170 >                                p = Math.abs(total % key.length);
171                                  ops -= 2;
172                                  continue;
173                              }
# Line 178 | Line 178 | public class CollectionLoops {
178                          ops -= 2;
179                          c.add(k);
180                          continue;
181 <                    }
182 <                    
181 >                    }
182 >
183                      total += LoopHelpers.compute6(k.intValue());
184                      --ops;
185                  }
# Line 192 | Line 192 | public class CollectionLoops {
192          }
193      }
194   }
195

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines