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

Comparing jsr166/src/test/loops/IteratorLoops.java (file contents):
Revision 1.1 by dl, Mon Nov 28 15:40:56 2005 UTC vs.
Revision 1.2 by jsr166, Tue Nov 29 08:58:22 2005 UTC

# Line 10 | Line 10 | import java.util.*;
10   * Estimates time per iteration of collection iterators.  Preloads
11   * most elements, but adds about 1/8 of them dynamically to preclude
12   * overly clever optimizations. The array of collections has
13 < * approximately exponentially different lengths, so chek both short
13 > * approximately exponentially different lengths, so check both short
14   * and long iterators.  Reports include times for adds and other
15   * checks, so overestimate times per iteration.
16   */
# Line 35 | Line 35 | public final class IteratorLoops {
35          Collection<Integer>[] colls =
36              (Collection<Integer>[])new Collection[NC];
37  
38 <        for (int k = 0; k < colls.length; ++k)
38 >        for (int k = 0; k < colls.length; ++k)
39              colls[k] = (Collection<Integer>)klass.newInstance();
40  
41 <        for (int i = 0; i < t; ++i)
41 >        for (int i = 0; i < t; ++i)
42              new IteratorLoops(colls).oneRun(n);
43  
44 <        if (mismatches != 0)
44 >        if (mismatches != 0)
45              throw new Error("Bad checksum :" + mismatches);
46      }
47  
48      private int elementCount;
49      private final Collection<Integer>[] cs;
50  
51 <    IteratorLoops(Collection<Integer>[] colls) {
52 <        cs = colls;
51 >    IteratorLoops(Collection<Integer>[] colls) {
52 >        cs = colls;
53          elementCount = 0;
54      }
55  
# Line 85 | Line 85 | public final class IteratorLoops {
85              }
86          }
87          return count;
88 <    }    
88 >    }
89  
90      void maybeAdd() {
91          int r = randomSeed;
92 <        r ^= r << 6;
93 <        r ^= r >>> 21;
92 >        r ^= r << 6;
93 >        r ^= r >>> 21;
94          r ^= r << 7;
95          randomSeed = r;
96 <        if ((r >>> 29) == 0)
96 >        if ((r >>> 29) == 0)
97              cs[r & (cs.length-1)].add(new Integer(elementCount++));
98 <    }    
98 >    }
99  
100      void preload(int n) {
101 <        for (int i = 0; i < cs.length; ++i)
101 >        for (int i = 0; i < cs.length; ++i)
102              cs[i].clear();
103          int k = (n - n / 8) / 2;
104          ArrayList<Integer> al = new ArrayList<Integer>(k+1);
105          for (int i = 0; i < cs.length; ++i) {
106              if (k > 0) {
107 <                for (int j = 0; j < k; ++j)
107 >                for (int j = 0; j < k; ++j)
108                      al.add(new Integer(elementCount++));
109                  cs[i].addAll(al);
110                  al.clear();
# Line 113 | Line 113 | public final class IteratorLoops {
113          }
114          // let GC settle down
115          try { Thread.sleep(500); } catch(Exception ex) { return; }
116 <    }    
116 >    }
117  
118  
119   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines