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

Comparing jsr166/src/test/loops/NavigableSetCheck.java (file contents):
Revision 1.4 by jsr166, Mon Nov 2 23:42:46 2009 UTC vs.
Revision 1.13 by jsr166, Mon Aug 10 03:13:33 2015 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   * @test
8   * @synopsis Times and checks basic set operations
9   */
10 import java.util.*;
10   import java.io.*;
11 + import java.util.*;
12  
13   public class NavigableSetCheck {
14  
# Line 25 | Line 25 | public class NavigableSetCheck {
25      }
26  
27      public static void main(String[] args) throws Exception {
28 <        Class setClass = null;
28 >        Class<?> setClass = null;
29          int numTests = 50;
30          int size = 50000;
31  
# Line 37 | Line 37 | public class NavigableSetCheck {
37              }
38          }
39  
40
40          if (args.length > 1)
41              numTests = Integer.parseInt(args[1]);
42  
# Line 46 | Line 45 | public class NavigableSetCheck {
45  
46          System.out.println("Testing " + setClass.getName() + " trials: " + numTests + " size: " + size);
47  
49
48          absentSize = 8;
49          while (absentSize < size) absentSize <<= 1;
50          absentMask = absentSize - 1;
# Line 59 | Line 57 | public class NavigableSetCheck {
57          for (int i = 0; i < size; ++i)
58              key[i] = new Integer(i * 2 + 1);
59  
62
60          for (int rep = 0; rep < numTests; ++rep) {
61              runTest(newSet(setClass), key);
62          }
63  
64          TestTimer.printStats();
68
65      }
66  
67 <    static NavigableSet newSet(Class cl) {
67 >    static NavigableSet newSet(Class<?> cl) {
68          try {
69              NavigableSet m = (NavigableSet) cl.newInstance();
70              return m;
# Line 77 | Line 73 | public class NavigableSetCheck {
73          }
74      }
75  
80
76      static void runTest(NavigableSet s, Integer[] key) {
77          shuffle(key);
78          int size = key.length;
# Line 96 | Line 91 | public class NavigableSetCheck {
91              }
92          }
93          timer.finish();
94 <        reallyAssert (sum == expect * iters);
94 >        reallyAssert(sum == expect * iters);
95      }
96  
97      static void t2(String nm, int n, NavigableSet s, Integer[] key, int expect) {
# Line 106 | Line 101 | public class NavigableSetCheck {
101              if (s.remove(key[i])) ++sum;
102          }
103          timer.finish();
104 <        reallyAssert (sum == expect);
104 >        reallyAssert(sum == expect);
105      }
106  
107      static void t3(String nm, int n, NavigableSet s, Integer[] key, int expect) {
# Line 116 | Line 111 | public class NavigableSetCheck {
111              if (s.add(key[i])) ++sum;
112          }
113          timer.finish();
114 <        reallyAssert (sum == expect);
114 >        reallyAssert(sum == expect);
115      }
116  
117      static void t4(String nm, int n, NavigableSet s, Integer[] key, int expect) {
# Line 126 | Line 121 | public class NavigableSetCheck {
121              if (s.contains(key[i])) ++sum;
122          }
123          timer.finish();
124 <        reallyAssert (sum == expect);
124 >        reallyAssert(sum == expect);
125      }
126  
127      static void t5(String nm, int n, NavigableSet s, Integer[] key, int expect) {
# Line 136 | Line 131 | public class NavigableSetCheck {
131              if (s.remove(key[i])) ++sum;
132          }
133          timer.finish();
134 <        reallyAssert (sum == expect);
134 >        reallyAssert(sum == expect);
135      }
136  
137      static void t6(String nm, int n, NavigableSet s, Integer[] k1, Integer[] k2) {
# Line 147 | Line 142 | public class NavigableSetCheck {
142              if (s.contains(k2[i & absentMask])) ++sum;
143          }
144          timer.finish();
145 <        reallyAssert (sum == n);
145 >        reallyAssert(sum == n);
146      }
147  
148      static void t7(String nm, int n, NavigableSet s, Integer[] k1, Integer[] k2) {
# Line 158 | Line 153 | public class NavigableSetCheck {
153              if (s.contains(k2[i & absentMask])) ++sum;
154          }
155          timer.finish();
156 <        reallyAssert (sum == n);
156 >        reallyAssert(sum == n);
157      }
158  
159      static void t8(String nm, int n, NavigableSet s, Integer[] key, int expect) {
# Line 168 | Line 163 | public class NavigableSetCheck {
163              if (s.contains(key[i])) ++sum;
164          }
165          timer.finish();
166 <        reallyAssert (sum == expect);
166 >        reallyAssert(sum == expect);
167      }
168  
174
169      static void higherTest(NavigableSet s) {
170          int sum = 0;
171          int iters = s.size();
# Line 182 | Line 176 | public class NavigableSetCheck {
176              e = s.higher(e);
177          }
178          timer.finish();
179 <        reallyAssert (sum == iters);
179 >        reallyAssert(sum == iters);
180      }
181  
182      static void lowerTest(NavigableSet s) {
# Line 195 | Line 189 | public class NavigableSetCheck {
189              e = s.higher(e);
190          }
191          timer.finish();
192 <        reallyAssert (sum == iters);
192 >        reallyAssert(sum == iters);
193      }
194  
195      static void ceilingTest(NavigableSet s) {
# Line 209 | Line 203 | public class NavigableSetCheck {
203                  ++sum;
204          }
205          timer.finish();
206 <        reallyAssert (sum == iters);
206 >        reallyAssert(sum == iters);
207      }
208  
209      static void floorTest(NavigableSet s) {
# Line 223 | Line 217 | public class NavigableSetCheck {
217                  ++sum;
218          }
219          timer.finish();
220 <        reallyAssert (sum == iters-1);
220 >        reallyAssert(sum == iters-1);
221      }
222  
229
223      static void ktest(NavigableSet s, int size, Integer[] key) {
224          timer.start("Contains               ", size);
225          int sum = 0;
# Line 234 | Line 227 | public class NavigableSetCheck {
227              if (s.contains(key[i])) ++sum;
228          }
229          timer.finish();
230 <        reallyAssert (sum == size);
230 >        reallyAssert(sum == size);
231      }
232  
240
233      static void ittest1(NavigableSet s, int size) {
234          int sum = 0;
235          timer.start("Iter Key               ", size);
# Line 246 | Line 238 | public class NavigableSetCheck {
238                  ++sum;
239          }
240          timer.finish();
241 <        reallyAssert (sum == size);
241 >        reallyAssert(sum == size);
242      }
243  
244      static void ittest(NavigableSet s, int size) {
# Line 261 | Line 253 | public class NavigableSetCheck {
253                  ++sum;
254          }
255          timer.finish();
256 <        reallyAssert (sum == size);
256 >        reallyAssert(sum == size);
257      }
258  
259      static void rittest(NavigableSet s, int size) {
260          rittest1(s, size);
261      }
262  
271
263      static void rtest(NavigableSet s, int size) {
264          timer.start("Remove (iterator)      ", size);
265          for (Iterator it = s.iterator(); it.hasNext(); ) {
# Line 278 | Line 269 | public class NavigableSetCheck {
269          timer.finish();
270      }
271  
281
282
272      static void dtest(NavigableSet s, int size, Integer[] key) {
273          timer.start("Add (addAll)           ", size * 2);
274          NavigableSet s2 = null;
# Line 292 | Line 281 | public class NavigableSetCheck {
281  
282          timer.start("Iter Equals            ", size * 2);
283          boolean eqt = s2.equals(s) && s.equals(s2);
284 <        reallyAssert (eqt);
284 >        reallyAssert(eqt);
285          timer.finish();
286  
287          timer.start("Iter HashCode          ", size * 2);
288          int shc = s.hashCode();
289          int s2hc = s2.hashCode();
290 <        reallyAssert (shc == s2hc);
290 >        reallyAssert(shc == s2hc);
291          timer.finish();
292  
293          timer.start("Add (present)          ", size);
# Line 312 | Line 301 | public class NavigableSetCheck {
301          timer.start("Iter Equals            ", size * 2);
302          eqt = s2.equals(s) && s.equals(s2);
303          if (as2)
304 <            reallyAssert (!eqt);
304 >            reallyAssert(!eqt);
305          timer.finish();
306  
307          timer.start("Iter HashCode          ", size * 2);
308          int s1h = s.hashCode();
309          int s2h = s2.hashCode();
310          if (as2)
311 <            reallyAssert (s1h != s2h);
311 >            reallyAssert(s1h != s2h);
312          timer.finish();
313  
314          timer.start("Clear                  ", size);
315          s.clear();
316          s2.clear();
317          timer.finish();
318 <        reallyAssert (s2.isEmpty() && s.isEmpty());
318 >        reallyAssert(s2.isEmpty() && s.isEmpty());
319      }
320  
332
333
321      static void test(NavigableSet s, Integer[] key) {
322          int size = key.length;
323  
# Line 371 | Line 358 | public class NavigableSetCheck {
358  
359          static void printStats() {
360              for (Iterator it = accum.entrySet().iterator(); it.hasNext(); ) {
361 <                Map.Entry e = (Map.Entry)(it.next());
362 <                Stats stats = ((Stats)(e.getValue()));
361 >                Map.Entry e = (Map.Entry) it.next();
362 >                Stats stats = (Stats) e.getValue();
363                  int n = stats.number;
364                  double t;
365                  if (n > 0)
# Line 391 | Line 378 | public class NavigableSetCheck {
378              startTime = System.currentTimeMillis();
379          }
380  
394
381          String classify() {
382              if (name.startsWith("Contains"))
383                  return "Contains               ";
# Line 408 | Line 394 | public class NavigableSetCheck {
394          void finish() {
395              long endTime = System.currentTimeMillis();
396              long time = endTime - startTime;
397 <            double timePerOp = ((double)time)/numOps;
397 >            double timePerOp = (double) time / numOps;
398  
399              Object st = accum.get(name);
400              if (st == null)
# Line 447 | Line 433 | public class NavigableSetCheck {
433  
434      static void shuffle(Integer[] keys) {
435          int size = keys.length;
436 <        for (int i=size; i>1; i--) {
436 >        for (int i = size; i > 1; i--) {
437              int r = rng.nextInt(i);
438              Integer t = keys[i-1];
439              keys[i-1] = keys[r];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines