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.1 by dl, Mon May 2 19:19:38 2005 UTC vs.
Revision 1.13 by jsr166, Wed Dec 31 17:00:58 2014 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/publicdomain/zero/1.0/
5 + */
6   /**
7   * @test
8   * @synopsis Times and checks basic map operations
9   */
5 import java.util.*;
10   import java.io.*;
11 + import java.util.*;
12  
13   public class IntMapCheck {
14      static int absentSize;
# Line 17 | Line 22 | public class IntMapCheck {
22      }
23  
24      public static void main(String[] args) throws Exception {
25 <        Class mapClass = java.util.concurrent.ConcurrentHashMap.class;
25 >        Class<?> mapClass = java.util.concurrent.ConcurrentHashMap.class;
26          int numTests = 50;
27 <        int size = 50000;
27 >        int size = 75000;
28  
29          if (args.length > 0) {
30              try {
31                  mapClass = Class.forName(args[0]);
32 <            } catch(ClassNotFoundException e) {
32 >            } catch (ClassNotFoundException e) {
33                  throw new RuntimeException("Class " + args[0] + " not found.");
34              }
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 41 | Line 46 | public class IntMapCheck {
46          System.out.println("Testing " + mapClass.getName() + " trials: " + numTests + " size: " + size);
47  
48          absentSize = 4;
49 <        while (absentSize <= size) absentSize <<= 1;
49 >        while (absentSize < size) absentSize <<= 1;
50          absentMask = absentSize-1;
51          absent = new Integer[absentSize];
52 <        for (int i = 0; i < absentSize; ++i)
53 <            absent[i] = new Integer(2 * (i - 1) + 1);
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)
55 >            absent[i] = Integer.valueOf(size + i + 1);
56  
57          Integer[] key = new Integer[size];
58 <        for (int i = 0; i < size; ++i)
59 <            key[i] = new Integer(2 * i);
58 >        for (int i = 0; i < size; ++i)
59 >            key[i] = Integer.valueOf(i);
60  
61          for (int rep = 0; rep < numTests; ++rep) {
55            shuffle(absent);
62              runTest(newMap(mapClass), key);
63 +            if ((rep & 3) == 3 && rep < numTests - 1) {
64 +                shuffle(key);
65 +                //                Thread.sleep(50);
66 +            }
67          }
68  
69          TestTimer.printStats();
# Line 63 | Line 73 | public class IntMapCheck {
73              stest(newMap(mapClass), size);
74      }
75  
76 <    static Map<Integer,Integer> newMap(Class cl) {
76 >    static Map<Integer,Integer> newMap(Class<?> cl) {
77          try {
78              Map m = (Map<Integer,Integer>)cl.newInstance();
79              return m;
80 <        } catch(Exception e) {
80 >        } catch (Exception e) {
81              throw new RuntimeException("Can't instantiate " + cl + ": " + e);
82          }
83      }
84  
85  
86      static void runTest(Map<Integer,Integer> s, Integer[] key) {
77        shuffle(key);
87          int size = key.length;
88          long startTime = System.nanoTime();
89          test(s, key);
90          long time = System.nanoTime() - startTime;
91      }
92  
93 <
85 <    static void t1(String nm, int n, Map<Integer,Integer> s, Integer[] key, int expect) {
93 >    static void t1(String nm, int n, Map<Integer,Integer> s, Integer[] key, int expect, int iters) {
94          int sum = 0;
87        int iters = 4;
95          timer.start(nm, n * iters);
96          for (int j = 0; j < iters; ++j) {
97              for (int i = 0; i < n; i++) {
98                  if (s.get(key[i]) != null) ++sum;
99              }
100          }
101 <        timer.finish();
102 <        reallyAssert (sum == expect * iters);
101 >        timer.finish();
102 >        reallyAssert(sum == expect * iters);
103 >    }
104 >
105 >    static void t1Boxed(String nm, int n, Map<Integer,Integer> s, Integer[] key, int expect) {
106 >        int sum = 0;
107 >        int iters = 8;
108 >        timer.start(nm, n * iters);
109 >        for (int j = 0; j < iters; ++j) {
110 >            for (int i = 0; i < n; i++) {
111 >                if (s.get(i) != i) ++sum;
112 >            }
113 >        }
114 >        timer.finish();
115 >        reallyAssert(sum == expect * iters);
116      }
117  
118 +
119      static void t2(String nm, int n, Map<Integer,Integer> s, Integer[] key, int expect) {
120          int sum = 0;
121          timer.start(nm, n);
122          for (int i = 0; i < n; i++) {
123              if (s.remove(key[i]) != null) ++sum;
124          }
125 <        timer.finish();
126 <        reallyAssert (sum == expect);
125 >        timer.finish();
126 >        reallyAssert(sum == expect);
127      }
128  
129      static void t3(String nm, int n, Map<Integer,Integer> s, Integer[] key, int expect) {
# Line 113 | Line 134 | public class IntMapCheck {
134              Integer v = absent[i & absentMask];
135              if (s.put(k, v) == null) ++sum;
136          }
137 <        timer.finish();
138 <        reallyAssert (sum == expect);
137 >        timer.finish();
138 >        reallyAssert(sum == expect);
139      }
140  
141      static void t4(String nm, int n, Map<Integer,Integer> s, Integer[] key, int expect) {
# Line 123 | Line 144 | public class IntMapCheck {
144          for (int i = 0; i < n; i++) {
145              if (s.containsKey(key[i])) ++sum;
146          }
147 <        timer.finish();
148 <        reallyAssert (sum == expect);
147 >        timer.finish();
148 >        reallyAssert(sum == expect);
149      }
150  
151      static void t5(String nm, int n, Map<Integer,Integer> s, Integer[] key, int expect) {
# Line 133 | 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();
158 <        reallyAssert (sum == expect);
157 >        timer.finish();
158 >        reallyAssert(sum == expect);
159      }
160  
161      static void t6(String nm, int n, Map<Integer,Integer> s, Integer[] k1, Integer[] k2) {
# Line 144 | 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();
169 <        reallyAssert (sum == n);
168 >        timer.finish();
169 >        reallyAssert(sum == n);
170      }
171  
172      static void t7(String nm, int n, Map<Integer,Integer> s, Integer[] k1, Integer[] k2) {
# Line 155 | Line 176 | public class IntMapCheck {
176              if (s.containsKey(k1[i])) ++sum;
177              if (s.containsKey(k2[i & absentMask])) ++sum;
178          }
179 <        timer.finish();
180 <        reallyAssert (sum == n);
179 >        timer.finish();
180 >        reallyAssert(sum == n);
181      }
182  
183      static void t8(String nm, int n, Map<Integer,Integer> s, Integer[] key, int expect) {
# Line 165 | 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();
190 <        reallyAssert (sum == expect);
189 >        timer.finish();
190 >        reallyAssert(sum == expect);
191      }
192  
193  
# Line 177 | 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();
202 <        reallyAssert (sum != 0);
201 >        timer.finish();
202 >        reallyAssert(sum != 0);
203      }
204  
205  
# Line 189 | Line 210 | public class IntMapCheck {
210          for (int i = 0; i < size; i++) {
211              if (ks.contains(key[i])) ++sum;
212          }
213 <        timer.finish();
214 <        reallyAssert (sum == size);
213 >        timer.finish();
214 >        reallyAssert(sum == size);
215      }
216  
217  
# Line 198 | Line 219 | public class IntMapCheck {
219          int sum = 0;
220          timer.start("Iter Key               ", size);
221          for (Iterator it = s.keySet().iterator(); it.hasNext(); ) {
222 <            if(it.next() != MISSING)
222 >            if (it.next() != MISSING)
223                  ++sum;
224          }
225 <        timer.finish();
226 <        reallyAssert (sum == size);
225 >        timer.finish();
226 >        //        if (sum != size)
227 >        //            System.out.println("iters " + sum + " size " + size);
228 >        reallyAssert(sum == size);
229      }
230  
231      static void ittest2(Map<Integer,Integer> s, int size) {
232          int sum = 0;
233          timer.start("Iter Value             ", size);
234          for (Iterator it = s.values().iterator(); it.hasNext(); ) {
235 <            if(it.next() != MISSING)
235 >            if (it.next() != MISSING)
236                  ++sum;
237          }
238 <        timer.finish();
239 <        reallyAssert (sum == size);
238 >        timer.finish();
239 >        //        if (sum != size)
240 >        //            System.out.println("iters " + sum + " size " + size);
241 >        reallyAssert(sum == size);
242      }
243      static void ittest3(Map<Integer,Integer> s, int size) {
244          int sum = 0;
245          timer.start("Iter Entry             ", size);
246          for (Iterator it = s.entrySet().iterator(); it.hasNext(); ) {
247 <            if(it.next() != MISSING)
247 >            if (it.next() != MISSING)
248                  ++sum;
249          }
250 <        timer.finish();
251 <        reallyAssert (sum == size);
250 >        timer.finish();
251 >        reallyAssert(sum == size);
252      }
253  
254      static void ittest4(Map<Integer,Integer> s, int size, int pos) {
255          IdentityHashMap seen = new IdentityHashMap(size);
256 <        reallyAssert (s.size() == size);
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 242 | Line 267 | public class IntMapCheck {
267              if (v != MISSING)
268                  ++sum;
269          }
270 <        reallyAssert (s.containsKey(k));
270 >        reallyAssert(s.containsKey(k));
271          it.remove();
272 <        reallyAssert (!s.containsKey(k));
272 >        reallyAssert(!s.containsKey(k));
273          while (it.hasNext()) {
274              Map.Entry<Integer,Integer> x = (Map.Entry<Integer,Integer>)(it.next());
275 <            Integer k2 = (Integer)x.getKey();
275 >            Integer k2 = x.getKey();
276              seen.put(k2, k2);
277              if (k2 != MISSING)
278                  ++sum;
279          }
280  
281 <        reallyAssert (s.size() == size-1);
281 >        reallyAssert(s.size() == size-1);
282          s.put(k, v);
283 <        reallyAssert (seen.size() == size);
284 <        timer.finish();
285 <        reallyAssert (sum == size);
286 <        reallyAssert (s.size() == size);
283 >        reallyAssert(seen.size() == size);
284 >        timer.finish();
285 >        reallyAssert(sum == size);
286 >        reallyAssert(s.size() == size);
287      }
288  
289  
290      static void ittest(Map<Integer,Integer> s, int size) {
291 <        ittest1(s, size);
292 <        ittest2(s, size);
293 <        ittest3(s, size);
294 <        //        for (int i = 0; i < size-1; ++i)
291 >        for (int i = 0; i < 4; ++i) {
292 >            ittest1(s, size);
293 >            ittest2(s, size);
294 >            ittest3(s, size);
295 >        }
296 >        //        for (int i = 0; i < size-1; ++i)
297          //            ittest4(s, size, i);
298      }
299  
# Line 278 | Line 305 | public class IntMapCheck {
305              if (en.nextElement() != MISSING)
306                  ++sum;
307          }
308 <        timer.finish();
309 <        reallyAssert (sum == size);
308 >        timer.finish();
309 >        reallyAssert(sum == size);
310      }
311  
312      static void entest2(Hashtable ht, int size) {
# Line 289 | Line 316 | public class IntMapCheck {
316              if (en.nextElement() != MISSING)
317                  ++sum;
318          }
319 <        timer.finish();
320 <        reallyAssert (sum == size);
319 >        timer.finish();
320 >        reallyAssert(sum == size);
321      }
322  
323  
# Line 298 | 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();
334 <        reallyAssert (sum == size);
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();
346 <        reallyAssert (sum == size);
345 >        timer.finish();
346 >        reallyAssert(sum == size);
347      }
348  
349      static void entest(Map<Integer,Integer> s, int size) {
350          if (s instanceof Hashtable) {
351 <            Hashtable ht = (Hashtable)s;
351 >            Hashtable ht = (Hashtable) s;
352              //            entest3(ht, size);
353              //            entest4(ht, size);
354              entest1(ht, size);
# Line 339 | Line 366 | public class IntMapCheck {
366              it.next();
367              it.remove();
368          }
369 <        timer.finish();
369 >        reallyAssert(s.isEmpty());
370 >        timer.finish();
371      }
372  
373 <    static void rvtest(Map<Integer,Integer> s, int size) {
374 <        timer.start("Remove (iterator)      ", size);
375 <        for (Iterator it = s.values().iterator(); it.hasNext(); ) {
376 <            it.next();
377 <            it.remove();
373 >    static void stest(Map<Integer,Integer> s, int size) throws Exception {
374 >        if (!(s instanceof Serializable))
375 >            return;
376 >        System.out.print("Serialize              : ");
377 >
378 >        for (int i = 0; i < size; i++) {
379 >            s.put(Integer.valueOf(i), Integer.valueOf(1));
380          }
381 <        timer.finish();
381 >
382 >        long startTime = System.nanoTime();
383 >
384 >        FileOutputStream fs = new FileOutputStream("IntMapCheck.dat");
385 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(fs));
386 >        out.writeObject(s);
387 >        out.close();
388 >
389 >        FileInputStream is = new FileInputStream("IntMapCheck.dat");
390 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(is));
391 >        Map<Integer,Integer> m = (Map<Integer,Integer>)in.readObject();
392 >
393 >        long endTime = System.nanoTime();
394 >        long time = endTime - startTime;
395 >
396 >        System.out.print(time + "ms");
397 >
398 >        if (s instanceof IdentityHashMap) return;
399 >        reallyAssert(s.equals(m));
400      }
401  
402  
403 <    static void dtest(Map<Integer,Integer> s, int size, Integer[] key) {
403 >    static void test(Map<Integer,Integer> s, Integer[] key) {
404 >        int size = key.length;
405 >
406 >        t3("Put (absent)           ", size, s, key, size);
407 >        reallyAssert(s.size() == size);
408 >        t1("Get (present)          ", size, s, key, size, 8);
409 >        t1Boxed("Get boxed (present)    ", size, s, key, size);
410 >        ittest1(s, size);
411 >        t3("Put (present)          ", size, s, key, 0);
412 >        reallyAssert(s.size() == size);
413 >        t7("ContainsKey            ", size, s, key, absent);
414 >        t4("ContainsKey            ", size, s, key, size);
415 >        ktest(s, size, key);
416 >        t4("ContainsKey            ", absentSize, s, absent, 0);
417 >        t6("Get                    ", size, s, key, absent);
418 >        t1("Get (present)          ", size, s, key, size, 8);
419 >        t1("Get (absent)           ", absentSize, s, absent, 0, 1);
420 >        reallyAssert(s.size() == size);
421 >        t2("Remove (absent)        ", absentSize, s, absent, 0);
422 >        reallyAssert(s.size() == size);
423 >        t5("Remove (present)       ", size, s, key, size / 2);
424 >        reallyAssert(s.size() == size / 2);
425 >        t1("Get                    ", size, s, key, size / 2, 8);
426 >        ittest1(s, size / 2);
427 >        t3("Put (half present)     ", size, s, key, size / 2);
428 >        reallyAssert(s.size() == size);
429 >        t1("Get (present)          ", size, s, key, size, 4);
430 >
431 >        entest(s, size);
432 >        t9(s);
433 >        reallyAssert(s.size() == size);
434 >        timer.start("Clear                  ", size);
435 >        s.clear();
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);
440 >        t3("Put (presized)         ", size, s, key, size);
441 >        t1("Get (present)          ", size, s, key, size, 4);
442 >        reallyAssert(s.size() == size);
443 >        ittest(s, size);
444 >        rtest(s, size);
445 >        reallyAssert(s.size() == 0);
446 >        timer.start("Clear                  ", size);
447 >        s.clear();
448 >        timer.finish();
449 >        t3("Put (presized)         ", size, s, key, size);
450 >
451          timer.start("Put (putAll)           ", size * 2);
452          Map<Integer,Integer> s2 = null;
453          try {
# Line 360 | 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();
462 >        reallyAssert(eqt);
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();
468 >        reallyAssert(shc == s2hc);
469 >        timer.finish();
470  
471 <        timer.start("Put (present)          ", size);
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;
477 >        for (Iterator i0 = s.entrySet().iterator(); i0.hasNext(); ) {
478 >            Map.Entry<Integer,Integer> me = (Map.Entry<Integer,Integer>)(i0.next());
479 >            if (s2.put(me.getKey(), me.getValue()) != null)
480 >                ++ipsum;
481 >        }
482 >        reallyAssert(ipsum == s.size());
483 >        timer.finish();
484  
485          timer.start("Iter EntrySet contains ", size * 2);
486          Set es2 = s2.entrySet();
# Line 384 | Line 489 | public class IntMapCheck {
489              Object entry = i1.next();
490              if (es2.contains(entry)) ++sum;
491          }
492 <        timer.finish();
493 <        reallyAssert (sum == size);
389 <
390 <        t6("Get                    ", size, s2, key, absent);
492 >        timer.finish();
493 >        reallyAssert(sum == size);
494  
495          Integer hold = s2.get(key[size-1]);
496          s2.put(key[size-1], absent[0]);
497          timer.start("Iter Equals            ", size * 2);
498          eqt = s2.equals(s) && s.equals(s2);
499 <        reallyAssert (!eqt);
500 <        timer.finish();
499 >        reallyAssert(!eqt);
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();
505 >        reallyAssert(s1h != s2h);
506 >        timer.finish();
507  
508          s2.put(key[size-1], hold);
509 <        timer.start("Remove (iterator)      ", size * 2);
509 >        timer.start("Remove (present)       ", size * 2);
510          Iterator s2i = s2.entrySet().iterator();
511          Set es = s.entrySet();
512          while (s2i.hasNext())
513              reallyAssert(es.remove(s2i.next()));
514 <        timer.finish();
514 >        timer.finish();
515  
516 <        if (!s.isEmpty()) System.out.println(s);
414 <        reallyAssert (s.isEmpty());
516 >        reallyAssert(s.isEmpty());
517  
518          timer.start("Clear                  ", size);
519          s2.clear();
520 <        timer.finish();
521 <        reallyAssert (s2.isEmpty() && s.isEmpty());
420 <    }
421 <
422 <    static void stest(Map<Integer,Integer> s, int size) throws Exception {
423 <        if (!(s instanceof Serializable))
424 <            return;
425 <        System.out.print("Serialize              : ");
426 <      
427 <        for (int i = 0; i < size; i++) {
428 <            s.put(new Integer(i), new Integer(1));
429 <        }
430 <
431 <        long startTime = System.nanoTime();
432 <
433 <        FileOutputStream fs = new FileOutputStream("IntMapCheck.dat");
434 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(fs));
435 <        out.writeObject(s);
436 <        out.close();
437 <
438 <        FileInputStream is = new FileInputStream("IntMapCheck.dat");
439 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(is));
440 <        Map<Integer,Integer> m = (Map<Integer,Integer>)in.readObject();
441 <
442 <        long endTime = System.nanoTime();
443 <        long time = endTime - startTime;
444 <
445 <        System.out.print(time + "ms");
446 <
447 <        if (s instanceof IdentityHashMap) return;
448 <        reallyAssert (s.equals(m));
449 <    }
450 <
451 <    
452 <    static void test(Map<Integer,Integer> s, Integer[] key) {
453 <        int size = key.length;
454 <
455 <        t3("Put (absent)           ", size, s, key, size);
456 <        t3("Put (present)          ", size, s, key, 0);
457 <        t7("ContainsKey            ", size, s, key, absent);
458 <        t4("ContainsKey            ", size, s, key, size);
459 <        ktest(s, size, key);
460 <        t4("ContainsKey            ", absentSize, s, absent, 0);
461 <        t6("Get                    ", size, s, key, absent);
462 <        t1("Get (present)          ", size, s, key, size);
463 <        t1("Get (absent)           ", absentSize, s, absent, 0);
464 <        t2("Remove (absent)        ", absentSize, s, absent, 0);
465 <        t5("Remove (present)       ", size, s, key, size / 2);
466 <        t3("Put (half present)     ", size, s, key, size / 2);
467 <
468 <        ittest(s, size);
469 <        entest(s, size);
470 <        t9(s);
471 <        rtest(s, size);
472 <
473 <        t4("ContainsKey            ", size, s, key, 0);
474 <        t2("Remove (absent)        ", size, s, key, 0);
475 <        t3("Put (presized)         ", size, s, key, size);
476 <        dtest(s, size, key);
520 >        timer.finish();
521 >        reallyAssert(s2.isEmpty() && s.isEmpty());
522      }
523  
524      static class TestTimer {
# Line 483 | 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()));
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;
542 <                long nano = Math.round(1000000.0 * t);
542 >                long nano = Math.round(t);
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 516 | 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  
568          void finish() {
569              long endTime = System.nanoTime();
570              long time = endTime - startTime;
571 <            double timePerOp = (((double)time)/numOps) / 1000000;
571 >            double timePerOp = ((double) time)/numOps;
572  
573              Object st = accum.get(name);
574              if (st == null)
# Line 558 | Line 603 | public class IntMapCheck {
603          Stats(double t) { least = t; }
604      }
605  
606 <    static Random rng = new Random();
606 >    static Random rng = new Random(3152688);
607  
608      static void shuffle(Integer[] keys) {
609          int size = keys.length;
610 <        for (int i=size; i>1; i--) {
610 >        for (int i = size; i > 1; i--) {
611              int r = rng.nextInt(i);
612              Integer t = keys[i-1];
613              keys[i-1] = keys[r];
# Line 571 | Line 616 | public class IntMapCheck {
616      }
617  
618   }
574

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines