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

Comparing jsr166/src/test/loops/IntMapCheck.java (file contents):
Revision 1.3 by dl, Fri Oct 23 19:57:06 2009 UTC vs.
Revision 1.4 by jsr166, Thu Oct 29 23:09:07 2009 UTC

# Line 35 | Line 35 | public class IntMapCheck {
35          }
36  
37  
38 <        if (args.length > 1)
38 >        if (args.length > 1)
39              numTests = Integer.parseInt(args[1]);
40  
41 <        if (args.length > 2)
41 >        if (args.length > 2)
42              size = Integer.parseInt(args[2]);
43  
44          boolean doSerializeTest = args.length > 3;
# Line 49 | Line 49 | public class IntMapCheck {
49          while (absentSize < size) absentSize <<= 1;
50          absentMask = absentSize-1;
51          absent = new Integer[absentSize];
52 <        for (int i = 0; i < absentSize/2; ++i)
52 >        for (int i = 0; i < absentSize/2; ++i)
53              absent[i] = Integer.valueOf(-i - 1);
54 <        for (int i = absentSize/2; i < absentSize; ++i)
54 >        for (int i = absentSize/2; i < absentSize; ++i)
55              absent[i] = Integer.valueOf(size + i + 1);
56  
57          Integer[] key = new Integer[size];
58 <        for (int i = 0; i < size; ++i)
58 >        for (int i = 0; i < size; ++i)
59              key[i] = Integer.valueOf(i);
60  
61          for (int rep = 0; rep < numTests; ++rep) {
# Line 98 | Line 98 | public class IntMapCheck {
98                  if (s.get(key[i]) != null) ++sum;
99              }
100          }
101 <        timer.finish();
101 >        timer.finish();
102          reallyAssert (sum == expect * iters);
103      }
104  
# Line 111 | Line 111 | public class IntMapCheck {
111                  if ((Integer)(s.get(i)) != i) ++sum;
112              }
113          }
114 <        timer.finish();
114 >        timer.finish();
115          reallyAssert (sum == expect * iters);
116      }
117  
# Line 122 | Line 122 | public class IntMapCheck {
122          for (int i = 0; i < n; i++) {
123              if (s.remove(key[i]) != null) ++sum;
124          }
125 <        timer.finish();
125 >        timer.finish();
126          reallyAssert (sum == expect);
127      }
128  
# Line 134 | Line 134 | public class IntMapCheck {
134              Integer v = absent[i & absentMask];
135              if (s.put(k, v) == null) ++sum;
136          }
137 <        timer.finish();
137 >        timer.finish();
138          reallyAssert (sum == expect);
139      }
140  
# Line 144 | Line 144 | public class IntMapCheck {
144          for (int i = 0; i < n; i++) {
145              if (s.containsKey(key[i])) ++sum;
146          }
147 <        timer.finish();
147 >        timer.finish();
148          reallyAssert (sum == expect);
149      }
150  
# Line 154 | Line 154 | public class IntMapCheck {
154          for (int i = n-2; i >= 0; i-=2) {
155              if (s.remove(key[i]) != null) ++sum;
156          }
157 <        timer.finish();
157 >        timer.finish();
158          reallyAssert (sum == expect);
159      }
160  
# Line 165 | Line 165 | public class IntMapCheck {
165              if (s.get(k1[i]) != null) ++sum;
166              if (s.get(k2[i & absentMask]) != null) ++sum;
167          }
168 <        timer.finish();
168 >        timer.finish();
169          reallyAssert (sum == n);
170      }
171  
# Line 176 | Line 176 | public class IntMapCheck {
176              if (s.containsKey(k1[i])) ++sum;
177              if (s.containsKey(k2[i & absentMask])) ++sum;
178          }
179 <        timer.finish();
179 >        timer.finish();
180          reallyAssert (sum == n);
181      }
182  
# Line 186 | Line 186 | public class IntMapCheck {
186          for (int i = 0; i < n; i++) {
187              if (s.get(key[i]) != null) ++sum;
188          }
189 <        timer.finish();
189 >        timer.finish();
190          reallyAssert (sum == expect);
191      }
192  
# Line 198 | Line 198 | public class IntMapCheck {
198          int step = absentSize / iters;
199          for (int i = 0; i < absentSize; i += step)
200              if (s.containsValue(absent[i])) ++sum;
201 <        timer.finish();
201 >        timer.finish();
202          reallyAssert (sum != 0);
203      }
204  
# Line 210 | Line 210 | public class IntMapCheck {
210          for (int i = 0; i < size; i++) {
211              if (ks.contains(key[i])) ++sum;
212          }
213 <        timer.finish();
213 >        timer.finish();
214          reallyAssert (sum == size);
215      }
216  
# Line 222 | Line 222 | public class IntMapCheck {
222              if(it.next() != MISSING)
223                  ++sum;
224          }
225 <        timer.finish();
226 <        //        if (sum != size)
225 >        timer.finish();
226 >        //        if (sum != size)
227          //            System.out.println("iters " + sum + " size " + size);
228          reallyAssert (sum == size);
229      }
# Line 235 | Line 235 | public class IntMapCheck {
235              if(it.next() != MISSING)
236                  ++sum;
237          }
238 <        timer.finish();
239 <        //        if (sum != size)
238 >        timer.finish();
239 >        //        if (sum != size)
240          //            System.out.println("iters " + sum + " size " + size);
241          reallyAssert (sum == size);
242      }
# Line 247 | Line 247 | public class IntMapCheck {
247              if(it.next() != MISSING)
248                  ++sum;
249          }
250 <        timer.finish();
250 >        timer.finish();
251          reallyAssert (sum == size);
252      }
253  
# Line 256 | Line 256 | public class IntMapCheck {
256          reallyAssert (s.size() == size);
257          int sum = 0;
258          timer.start("Iter XEntry            ", size);
259 <        Iterator it = s.entrySet().iterator();
259 >        Iterator it = s.entrySet().iterator();
260          Integer k = null;
261          Integer v = null;
262          for (int i = 0; i < size-pos; ++i) {
# Line 281 | Line 281 | public class IntMapCheck {
281          reallyAssert (s.size() == size-1);
282          s.put(k, v);
283          reallyAssert (seen.size() == size);
284 <        timer.finish();
284 >        timer.finish();
285          reallyAssert (sum == size);
286          reallyAssert (s.size() == size);
287      }
# Line 293 | Line 293 | public class IntMapCheck {
293              ittest2(s, size);
294              ittest3(s, size);
295          }
296 <        //        for (int i = 0; i < size-1; ++i)
296 >        //        for (int i = 0; i < size-1; ++i)
297          //            ittest4(s, size, i);
298      }
299  
# Line 305 | Line 305 | public class IntMapCheck {
305              if (en.nextElement() != MISSING)
306                  ++sum;
307          }
308 <        timer.finish();
308 >        timer.finish();
309          reallyAssert (sum == size);
310      }
311  
# Line 316 | Line 316 | public class IntMapCheck {
316              if (en.nextElement() != MISSING)
317                  ++sum;
318          }
319 <        timer.finish();
319 >        timer.finish();
320          reallyAssert (sum == size);
321      }
322  
# Line 325 | Line 325 | public class IntMapCheck {
325          int sum = 0;
326  
327          timer.start("Iterf Enumeration Key  ", size);
328 <        Enumeration en = ht.keys();
328 >        Enumeration en = ht.keys();
329          for (int i = 0; i < size; ++i) {
330              if (en.nextElement() != MISSING)
331                  ++sum;
332          }
333 <        timer.finish();
333 >        timer.finish();
334          reallyAssert (sum == size);
335      }
336  
337      static void entest4(Hashtable ht, int size) {
338          int sum = 0;
339          timer.start("Iterf Enumeration Value", size);
340 <        Enumeration en = ht.elements();
340 >        Enumeration en = ht.elements();
341          for (int i = 0; i < size; ++i) {
342              if (en.nextElement() != MISSING)
343                  ++sum;
344          }
345 <        timer.finish();
345 >        timer.finish();
346          reallyAssert (sum == size);
347      }
348  
# Line 367 | Line 367 | public class IntMapCheck {
367              it.remove();
368          }
369          reallyAssert(s.isEmpty());
370 <        timer.finish();
370 >        timer.finish();
371      }
372  
373      static void stest(Map<Integer,Integer> s, int size) throws Exception {
374 <        if (!(s instanceof Serializable))
374 >        if (!(s instanceof Serializable))
375              return;
376          System.out.print("Serialize              : ");
377 <      
377 >
378          for (int i = 0; i < size; i++) {
379              s.put(Integer.valueOf(i), Integer.valueOf(1));
380          }
# Line 399 | Line 399 | public class IntMapCheck {
399          reallyAssert (s.equals(m));
400      }
401  
402 <    
402 >
403      static void test(Map<Integer,Integer> s, Integer[] key) {
404          int size = key.length;
405  
# Line 433 | Line 433 | public class IntMapCheck {
433          reallyAssert(s.size() == size);
434          timer.start("Clear                  ", size);
435          s.clear();
436 <        timer.finish();
436 >        timer.finish();
437          t1("Get (absent)           ", size, s, key, 0, 1);
438          t4("ContainsKey            ", size, s, key, 0);
439          t2("Remove (absent)        ", size, s, key, 0);
# Line 445 | Line 445 | public class IntMapCheck {
445          reallyAssert(s.size() == 0);
446          timer.start("Clear                  ", size);
447          s.clear();
448 <        timer.finish();
448 >        timer.finish();
449          t3("Put (presized)         ", size, s, key, size);
450  
451          timer.start("Put (putAll)           ", size * 2);
# Line 455 | Line 455 | public class IntMapCheck {
455              s2.putAll(s);
456          }
457          catch (Exception e) { e.printStackTrace(); return; }
458 <        timer.finish();
459 <    
458 >        timer.finish();
459 >
460          timer.start("Iter Equals            ", size * 2);
461          boolean eqt = s2.equals(s) && s.equals(s2);
462          reallyAssert (eqt);
463 <        timer.finish();
463 >        timer.finish();
464  
465          timer.start("Iter HashCode          ", size * 2);
466          int shc = s.hashCode();
467          int s2hc = s2.hashCode();
468          reallyAssert (shc == s2hc);
469 <        timer.finish();
469 >        timer.finish();
470  
471          timer.start("Put (present)          ", size * 2);
472          s2.putAll(s);
473 <        timer.finish();
473 >        timer.finish();
474  
475          timer.start("Put (present)          ", size);
476          int ipsum = 0;
# Line 480 | Line 480 | public class IntMapCheck {
480                  ++ipsum;
481          }
482          reallyAssert (ipsum == s.size());
483 <        timer.finish();
483 >        timer.finish();
484  
485          timer.start("Iter EntrySet contains ", size * 2);
486          Set es2 = s2.entrySet();
# Line 489 | Line 489 | public class IntMapCheck {
489              Object entry = i1.next();
490              if (es2.contains(entry)) ++sum;
491          }
492 <        timer.finish();
492 >        timer.finish();
493          reallyAssert (sum == size);
494  
495          Integer hold = s2.get(key[size-1]);
# Line 497 | Line 497 | public class IntMapCheck {
497          timer.start("Iter Equals            ", size * 2);
498          eqt = s2.equals(s) && s.equals(s2);
499          reallyAssert (!eqt);
500 <        timer.finish();
500 >        timer.finish();
501  
502          timer.start("Iter HashCode          ", size * 2);
503          int s1h = s.hashCode();
504          int s2h = s2.hashCode();
505          reallyAssert (s1h != s2h);
506 <        timer.finish();
506 >        timer.finish();
507  
508          s2.put(key[size-1], hold);
509          timer.start("Remove (present)       ", size * 2);
# Line 511 | Line 511 | public class IntMapCheck {
511          Set es = s.entrySet();
512          while (s2i.hasNext())
513              reallyAssert(es.remove(s2i.next()));
514 <        timer.finish();
514 >        timer.finish();
515  
516          reallyAssert (s.isEmpty());
517  
518          timer.start("Clear                  ", size);
519          s2.clear();
520 <        timer.finish();
520 >        timer.finish();
521          reallyAssert (s2.isEmpty() && s.isEmpty());
522      }
523  
# Line 528 | Line 528 | public class IntMapCheck {
528          private String cname;
529  
530          static final java.util.TreeMap accum = new java.util.TreeMap();
531 <    
531 >
532          static void printStats() {
533              for (Iterator it = accum.entrySet().iterator(); it.hasNext(); ) {
534                  Map.Entry e = (Map.Entry)(it.next());
535                  Stats stats = ((Stats)(e.getValue()));
536                  long n = stats.number;
537                  double t;
538 <                if (n > 0)
538 >                if (n > 0)
539                      t = stats.sum / n;
540                  else
541                      t = stats.least;
# Line 543 | Line 543 | public class IntMapCheck {
543                  System.out.println(e.getKey() + ": " + nano);
544              }
545          }
546 <    
546 >
547          void start(String name, long numOps) {
548              this.name = name;
549              this.cname = classify();
550              this.numOps = numOps;
551              startTime = System.nanoTime();
552          }
553 <    
553 >
554  
555          String classify() {
556              if (name.startsWith("Get"))
# Line 561 | Line 561 | public class IntMapCheck {
561                  return "Remove                 ";
562              else if (name.startsWith("Iter"))
563                  return "Iter                   ";
564 <            else
564 >            else
565                  return null;
566          }
567  
# Line 616 | Line 616 | public class IntMapCheck {
616      }
617  
618   }
619

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines