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.16 by jsr166, Sun Oct 23 03:03:23 2016 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();
74 <            return m;
69 >            return (NavigableMap) cl.getConstructor().newInstance();
70          } catch (Exception e) {
71              throw new RuntimeException("Can't instantiate " + cl + ": " + e);
72          }
73      }
74  
80
75      static void runTest(NavigableMap s, Integer[] key) {
76          shuffle(key);
77          int size = key.length;
# Line 171 | Line 165 | public class NavigableMapCheck {
165          reallyAssert(sum == expect);
166      }
167  
174
168      static void t9(NavigableMap s) {
169          int sum = 0;
170          int iters = 20;
# Line 237 | Line 230 | public class NavigableMapCheck {
230          reallyAssert(sum == iters-1);
231      }
232  
240
233      static void ktest(NavigableMap s, int size, Integer[] key) {
234          timer.start("ContainsKey            ", size);
235          Set ks = s.keySet();
# Line 249 | Line 241 | public class NavigableMapCheck {
241          reallyAssert(sum == size);
242      }
243  
252
244      static void ittest1(NavigableMap s, int size) {
245          int sum = 0;
246          timer.start("Iter Key               ", size);
# Line 299 | Line 290 | public class NavigableMapCheck {
290          reallyAssert(sum == size);
291      }
292  
302
293      static void rittest(NavigableMap s, int size) {
294          rittest1(s, size);
295          //        rittest2(s, size);
296      }
297  
308
298      static void rtest(NavigableMap s, int size) {
299          timer.start("Remove (iterator)      ", size);
300          for (Iterator it = s.keySet().iterator(); it.hasNext(); ) {
# Line 324 | Line 313 | public class NavigableMapCheck {
313          timer.finish();
314      }
315  
327
316      static void dtest(NavigableMap s, int size, Integer[] key) {
317          timer.start("Put (putAll)           ", size * 2);
318 <        NavigableMap s2 = null;
318 >        final NavigableMap s2;
319          try {
320 <            s2 = (NavigableMap) (s.getClass().newInstance());
320 >            s2 = (NavigableMap) s.getClass().getConstructor().newInstance();
321              s2.putAll(s);
322          }
323          catch (Exception e) { e.printStackTrace(); return; }
# Line 391 | Line 379 | public class NavigableMapCheck {
379          reallyAssert(s2.isEmpty() && s.isEmpty());
380      }
381  
394
395
382      static void test(NavigableMap s, Integer[] key) {
383          int size = key.length;
384  
# Line 454 | Line 440 | public class NavigableMapCheck {
440              startTime = System.currentTimeMillis();
441          }
442  
457
443          String classify() {
444              if (name.startsWith("Get"))
445                  return "Get                    ";
# Line 494 | Line 479 | public class NavigableMapCheck {
479                      if (timePerOp < stats.least) stats.least = timePerOp;
480                  }
481              }
497
482          }
499
483      }
484  
485      static class Stats {
# Line 510 | Line 493 | public class NavigableMapCheck {
493  
494      static void shuffle(Integer[] keys) {
495          int size = keys.length;
496 <        for (int i=size; i>1; i--) {
496 >        for (int i = size; i > 1; i--) {
497              int r = rng.nextInt(i);
498              Integer t = keys[i-1];
499              keys[i-1] = keys[r];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines