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.2 by dl, Mon May 9 19:33:30 2005 UTC vs.
Revision 1.7 by jsr166, Wed Sep 1 07:47:27 2010 UTC

# Line 32 | Line 32 | public class NavigableSetCheck {
32          if (args.length > 0) {
33              try {
34                  setClass = Class.forName(args[0]);
35 <            } catch(ClassNotFoundException e) {
35 >            } catch (ClassNotFoundException e) {
36                  throw new RuntimeException("Class " + args[0] + " not found.");
37              }
38          }
39  
40  
41 <        if (args.length > 1)
41 >        if (args.length > 1)
42              numTests = Integer.parseInt(args[1]);
43  
44 <        if (args.length > 2)
44 >        if (args.length > 2)
45              size = Integer.parseInt(args[2]);
46  
47          System.out.println("Testing " + setClass.getName() + " trials: " + numTests + " size: " + size);
# Line 52 | Line 52 | public class NavigableSetCheck {
52          absentMask = absentSize - 1;
53          absent = new Integer[absentSize];
54  
55 <        for (int i = 0; i < absentSize; ++i)
55 >        for (int i = 0; i < absentSize; ++i)
56              absent[i] = new Integer(i * 2);
57  
58          Integer[] key = new Integer[size];
59 <        for (int i = 0; i < size; ++i)
59 >        for (int i = 0; i < size; ++i)
60              key[i] = new Integer(i * 2 + 1);
61  
62  
# Line 70 | Line 70 | public class NavigableSetCheck {
70  
71      static NavigableSet newSet(Class cl) {
72          try {
73 <            NavigableSet m = (NavigableSet)cl.newInstance();
73 >            NavigableSet m = (NavigableSet) cl.newInstance();
74              return m;
75 <        } catch(Exception e) {
75 >        } catch (Exception e) {
76              throw new RuntimeException("Can't instantiate " + cl + ": " + e);
77          }
78      }
# Line 95 | Line 95 | public class NavigableSetCheck {
95                  if (s.contains(key[i])) ++sum;
96              }
97          }
98 <        timer.finish();
99 <        reallyAssert (sum == expect * iters);
98 >        timer.finish();
99 >        reallyAssert(sum == expect * iters);
100      }
101  
102      static void t2(String nm, int n, NavigableSet s, Integer[] key, int expect) {
# Line 105 | Line 105 | public class NavigableSetCheck {
105          for (int i = 0; i < n; i++) {
106              if (s.remove(key[i])) ++sum;
107          }
108 <        timer.finish();
109 <        reallyAssert (sum == expect);
108 >        timer.finish();
109 >        reallyAssert(sum == expect);
110      }
111  
112      static void t3(String nm, int n, NavigableSet s, Integer[] key, int expect) {
# Line 115 | Line 115 | public class NavigableSetCheck {
115          for (int i = 0; i < n; i++) {
116              if (s.add(key[i])) ++sum;
117          }
118 <        timer.finish();
119 <        reallyAssert (sum == expect);
118 >        timer.finish();
119 >        reallyAssert(sum == expect);
120      }
121  
122      static void t4(String nm, int n, NavigableSet s, Integer[] key, int expect) {
# Line 125 | Line 125 | public class NavigableSetCheck {
125          for (int i = 0; i < n; i++) {
126              if (s.contains(key[i])) ++sum;
127          }
128 <        timer.finish();
129 <        reallyAssert (sum == expect);
128 >        timer.finish();
129 >        reallyAssert(sum == expect);
130      }
131  
132      static void t5(String nm, int n, NavigableSet s, Integer[] key, int expect) {
# Line 135 | Line 135 | public class NavigableSetCheck {
135          for (int i = n-2; i >= 0; i-=2) {
136              if (s.remove(key[i])) ++sum;
137          }
138 <        timer.finish();
139 <        reallyAssert (sum == expect);
138 >        timer.finish();
139 >        reallyAssert(sum == expect);
140      }
141  
142      static void t6(String nm, int n, NavigableSet s, Integer[] k1, Integer[] k2) {
# Line 146 | Line 146 | public class NavigableSetCheck {
146              if (s.contains(k1[i])) ++sum;
147              if (s.contains(k2[i & absentMask])) ++sum;
148          }
149 <        timer.finish();
150 <        reallyAssert (sum == n);
149 >        timer.finish();
150 >        reallyAssert(sum == n);
151      }
152  
153      static void t7(String nm, int n, NavigableSet s, Integer[] k1, Integer[] k2) {
# Line 157 | Line 157 | public class NavigableSetCheck {
157              if (s.contains(k1[i])) ++sum;
158              if (s.contains(k2[i & absentMask])) ++sum;
159          }
160 <        timer.finish();
161 <        reallyAssert (sum == n);
160 >        timer.finish();
161 >        reallyAssert(sum == n);
162      }
163  
164      static void t8(String nm, int n, NavigableSet s, Integer[] key, int expect) {
# Line 167 | Line 167 | public class NavigableSetCheck {
167          for (int i = 0; i < n; i++) {
168              if (s.contains(key[i])) ++sum;
169          }
170 <        timer.finish();
171 <        reallyAssert (sum == expect);
170 >        timer.finish();
171 >        reallyAssert(sum == expect);
172      }
173  
174  
# Line 181 | Line 181 | public class NavigableSetCheck {
181              ++sum;
182              e = s.higher(e);
183          }
184 <        timer.finish();
185 <        reallyAssert (sum == iters);
184 >        timer.finish();
185 >        reallyAssert(sum == iters);
186      }
187  
188      static void lowerTest(NavigableSet s) {
# Line 194 | Line 194 | public class NavigableSetCheck {
194              ++sum;
195              e = s.higher(e);
196          }
197 <        timer.finish();
198 <        reallyAssert (sum == iters);
197 >        timer.finish();
198 >        reallyAssert(sum == iters);
199      }
200  
201      static void ceilingTest(NavigableSet s) {
# Line 208 | Line 208 | public class NavigableSetCheck {
208              if (e != null)
209                  ++sum;
210          }
211 <        timer.finish();
212 <        reallyAssert (sum == iters);
211 >        timer.finish();
212 >        reallyAssert(sum == iters);
213      }
214  
215      static void floorTest(NavigableSet s) {
# Line 222 | Line 222 | public class NavigableSetCheck {
222              if (e != null)
223                  ++sum;
224          }
225 <        timer.finish();
226 <        reallyAssert (sum == iters-1);
225 >        timer.finish();
226 >        reallyAssert(sum == iters-1);
227      }
228  
229  
# Line 233 | Line 233 | public class NavigableSetCheck {
233          for (int i = 0; i < size; i++) {
234              if (s.contains(key[i])) ++sum;
235          }
236 <        timer.finish();
237 <        reallyAssert (sum == size);
236 >        timer.finish();
237 >        reallyAssert(sum == size);
238      }
239  
240  
# Line 242 | Line 242 | public class NavigableSetCheck {
242          int sum = 0;
243          timer.start("Iter Key               ", size);
244          for (Iterator it = s.iterator(); it.hasNext(); ) {
245 <            if(it.next() != MISSING)
245 >            if (it.next() != MISSING)
246                  ++sum;
247          }
248 <        timer.finish();
249 <        reallyAssert (sum == size);
248 >        timer.finish();
249 >        reallyAssert(sum == size);
250      }
251  
252      static void ittest(NavigableSet s, int size) {
# Line 257 | Line 257 | public class NavigableSetCheck {
257          int sum = 0;
258          timer.start("Desc Iter Key          ", size);
259          for (Iterator it = s.descendingIterator(); it.hasNext(); ) {
260 <            if(it.next() != MISSING)
260 >            if (it.next() != MISSING)
261                  ++sum;
262          }
263 <        timer.finish();
264 <        reallyAssert (sum == size);
263 >        timer.finish();
264 >        reallyAssert(sum == size);
265      }
266  
267      static void rittest(NavigableSet s, int size) {
# Line 275 | Line 275 | public class NavigableSetCheck {
275              it.next();
276              it.remove();
277          }
278 <        timer.finish();
278 >        timer.finish();
279      }
280  
281  
# Line 288 | Line 288 | public class NavigableSetCheck {
288              s2.addAll(s);
289          }
290          catch (Exception e) { e.printStackTrace(); return; }
291 <        timer.finish();
292 <    
291 >        timer.finish();
292 >
293          timer.start("Iter Equals            ", size * 2);
294          boolean eqt = s2.equals(s) && s.equals(s2);
295 <        reallyAssert (eqt);
296 <        timer.finish();
295 >        reallyAssert(eqt);
296 >        timer.finish();
297  
298          timer.start("Iter HashCode          ", size * 2);
299          int shc = s.hashCode();
300          int s2hc = s2.hashCode();
301 <        reallyAssert (shc == s2hc);
302 <        timer.finish();
301 >        reallyAssert(shc == s2hc);
302 >        timer.finish();
303  
304          timer.start("Add (present)          ", size);
305          s2.addAll(s);
306 <        timer.finish();
306 >        timer.finish();
307  
308          t6("Contains               ", size, s2, key, absent);
309  
# Line 312 | Line 312 | public class NavigableSetCheck {
312          timer.start("Iter Equals            ", size * 2);
313          eqt = s2.equals(s) && s.equals(s2);
314          if (as2)
315 <            reallyAssert (!eqt);
316 <        timer.finish();
315 >            reallyAssert(!eqt);
316 >        timer.finish();
317  
318          timer.start("Iter HashCode          ", size * 2);
319          int s1h = s.hashCode();
320          int s2h = s2.hashCode();
321          if (as2)
322 <            reallyAssert (s1h != s2h);
323 <        timer.finish();
322 >            reallyAssert(s1h != s2h);
323 >        timer.finish();
324  
325          timer.start("Clear                  ", size);
326          s.clear();
327          s2.clear();
328 <        timer.finish();
329 <        reallyAssert (s2.isEmpty() && s.isEmpty());
328 >        timer.finish();
329 >        reallyAssert(s2.isEmpty() && s.isEmpty());
330      }
331  
332  
333 <    
333 >
334      static void test(NavigableSet s, Integer[] key) {
335          int size = key.length;
336  
# Line 368 | Line 368 | public class NavigableSetCheck {
368          private String cname;
369  
370          static final java.util.TreeMap accum = new java.util.TreeMap();
371 <    
371 >
372          static void printStats() {
373              for (Iterator it = accum.entrySet().iterator(); it.hasNext(); ) {
374 <                Map.Entry e = (Map.Entry)(it.next());
375 <                Stats stats = ((Stats)(e.getValue()));
374 >                Map.Entry e = (Map.Entry) it.next();
375 >                Stats stats = (Stats) e.getValue();
376                  int n = stats.number;
377                  double t;
378 <                if (n > 0)
378 >                if (n > 0)
379                      t = stats.sum / n;
380                  else
381                      t = stats.least;
# Line 383 | Line 383 | public class NavigableSetCheck {
383                  System.out.println(e.getKey() + ": " + nano);
384              }
385          }
386 <    
386 >
387          void start(String name, long numOps) {
388              this.name = name;
389              this.cname = classify();
390              this.numOps = numOps;
391              startTime = System.currentTimeMillis();
392          }
393 <    
393 >
394  
395          String classify() {
396              if (name.startsWith("Contains"))
# Line 401 | Line 401 | public class NavigableSetCheck {
401                  return "Remove                 ";
402              else if (name.startsWith("Iter"))
403                  return "Iter                   ";
404 <            else
404 >            else
405                  return null;
406          }
407  
408          void finish() {
409              long endTime = System.currentTimeMillis();
410              long time = endTime - startTime;
411 <            double timePerOp = ((double)time)/numOps;
411 >            double timePerOp = (double) time / numOps;
412  
413              Object st = accum.get(name);
414              if (st == null)
# Line 456 | Line 456 | public class NavigableSetCheck {
456      }
457  
458   }
459

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines