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

Comparing jsr166/src/test/loops/NavigableMapCheck.java (file contents):
Revision 1.9 by jsr166, Wed Sep 1 07:47:27 2010 UTC vs.
Revision 1.15 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 map operations
9   */
10 import java.util.*;
10   import java.io.*;
11 + import java.util.*;
12  
13   public class NavigableMapCheck {
14  
# Line 25 | Line 25 | public class NavigableMapCheck {
25      }
26  
27      public static void main(String[] args) throws Exception {
28 <        Class mapClass = null;
28 >        Class<?> mapClass = null;
29          int numTests = 50;
30          int size = 50000;
31  
# Line 37 | Line 37 | public class NavigableMapCheck {
37              }
38          }
39  
40
40          if (args.length > 1)
41              numTests = Integer.parseInt(args[1]);
42  
# Line 46 | Line 45 | public class NavigableMapCheck {
45  
46          System.out.println("Testing " + mapClass.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 NavigableMapCheck {
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(newMap(mapClass), key);
62          }
63  
64          TestTimer.printStats();
68
65      }
66  
67 <    static NavigableMap newMap(Class cl) {
67 >    static NavigableMap newMap(Class<?> cl) {
68          try {
69              NavigableMap m = (NavigableMap) cl.newInstance();
70              return m;
# Line 77 | Line 73 | public class NavigableMapCheck {
73          }
74      }
75  
80
76      static void runTest(NavigableMap s, Integer[] key) {
77          shuffle(key);
78          int size = key.length;
# Line 171 | Line 166 | public class NavigableMapCheck {
166          reallyAssert(sum == expect);
167      }
168  
174
169      static void t9(NavigableMap s) {
170          int sum = 0;
171          int iters = 20;
# Line 237 | Line 231 | public class NavigableMapCheck {
231          reallyAssert(sum == iters-1);
232      }
233  
240
234      static void ktest(NavigableMap s, int size, Integer[] key) {
235          timer.start("ContainsKey            ", size);
236          Set ks = s.keySet();
# Line 249 | Line 242 | public class NavigableMapCheck {
242          reallyAssert(sum == size);
243      }
244  
252
245      static void ittest1(NavigableMap s, int size) {
246          int sum = 0;
247          timer.start("Iter Key               ", size);
# Line 299 | Line 291 | public class NavigableMapCheck {
291          reallyAssert(sum == size);
292      }
293  
302
294      static void rittest(NavigableMap s, int size) {
295          rittest1(s, size);
296          //        rittest2(s, size);
297      }
298  
308
299      static void rtest(NavigableMap s, int size) {
300          timer.start("Remove (iterator)      ", size);
301          for (Iterator it = s.keySet().iterator(); it.hasNext(); ) {
# Line 324 | Line 314 | public class NavigableMapCheck {
314          timer.finish();
315      }
316  
327
317      static void dtest(NavigableMap s, int size, Integer[] key) {
318          timer.start("Put (putAll)           ", size * 2);
319          NavigableMap s2 = null;
# Line 391 | Line 380 | public class NavigableMapCheck {
380          reallyAssert(s2.isEmpty() && s.isEmpty());
381      }
382  
394
395
383      static void test(NavigableMap s, Integer[] key) {
384          int size = key.length;
385  
# Line 454 | Line 441 | public class NavigableMapCheck {
441              startTime = System.currentTimeMillis();
442          }
443  
457
444          String classify() {
445              if (name.startsWith("Get"))
446                  return "Get                    ";
# Line 494 | Line 480 | public class NavigableMapCheck {
480                      if (timePerOp < stats.least) stats.least = timePerOp;
481                  }
482              }
497
483          }
499
484      }
485  
486      static class Stats {
# Line 510 | Line 494 | public class NavigableMapCheck {
494  
495      static void shuffle(Integer[] keys) {
496          int size = keys.length;
497 <        for (int i=size; i>1; i--) {
497 >        for (int i = size; i > 1; i--) {
498              int r = rng.nextInt(i);
499              Integer t = keys[i-1];
500              keys[i-1] = keys[r];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines