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.9 by jsr166, Wed Sep 1 07:47:27 2010 UTC vs.
Revision 1.15 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 IntMapCheck {
14      static int absentSize;
# Line 22 | 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 = 75000;
28  
# Line 34 | Line 34 | public class IntMapCheck {
34              }
35          }
36  
37
37          if (args.length > 1)
38              numTests = Integer.parseInt(args[1]);
39  
# Line 68 | Line 67 | public class IntMapCheck {
67  
68          TestTimer.printStats();
69  
71
70          if (doSerializeTest)
71              stest(newMap(mapClass), size);
72      }
73  
74 <    static Map<Integer,Integer> newMap(Class cl) {
74 >    static Map<Integer,Integer> newMap(Class<?> cl) {
75          try {
76 <            Map m = (Map<Integer,Integer>)cl.newInstance();
79 <            return m;
76 >            return (Map<Integer,Integer>) cl.getConstructor().newInstance();
77          } catch (Exception e) {
78              throw new RuntimeException("Can't instantiate " + cl + ": " + e);
79          }
80      }
81  
85
82      static void runTest(Map<Integer,Integer> s, Integer[] key) {
83          int size = key.length;
84          long startTime = System.nanoTime();
# Line 115 | Line 111 | public class IntMapCheck {
111          reallyAssert(sum == expect * iters);
112      }
113  
118
114      static void t2(String nm, int n, Map<Integer,Integer> s, Integer[] key, int expect) {
115          int sum = 0;
116          timer.start(nm, n);
# Line 190 | Line 185 | public class IntMapCheck {
185          reallyAssert(sum == expect);
186      }
187  
193
188      static void t9(Map<Integer,Integer> s) {
189          int sum = 0;
190          int iters = 20;
# Line 202 | Line 196 | public class IntMapCheck {
196          reallyAssert(sum != 0);
197      }
198  
205
199      static void ktest(Map<Integer,Integer> s, int size, Integer[] key) {
200          timer.start("ContainsKey            ", size);
201          Set ks = s.keySet();
# Line 214 | Line 207 | public class IntMapCheck {
207          reallyAssert(sum == size);
208      }
209  
217
210      static void ittest1(Map<Integer,Integer> s, int size) {
211          int sum = 0;
212          timer.start("Iter Key               ", size);
# Line 286 | Line 278 | public class IntMapCheck {
278          reallyAssert(s.size() == size);
279      }
280  
289
281      static void ittest(Map<Integer,Integer> s, int size) {
282          for (int i = 0; i < 4; ++i) {
283              ittest1(s, size);
# Line 320 | Line 311 | public class IntMapCheck {
311          reallyAssert(sum == size);
312      }
313  
323
314      static void entest3(Hashtable ht, int size) {
315          int sum = 0;
316  
# Line 399 | Line 389 | public class IntMapCheck {
389          reallyAssert(s.equals(m));
390      }
391  
402
392      static void test(Map<Integer,Integer> s, Integer[] key) {
393          int size = key.length;
394  
# Line 449 | Line 438 | public class IntMapCheck {
438          t3("Put (presized)         ", size, s, key, size);
439  
440          timer.start("Put (putAll)           ", size * 2);
441 <        Map<Integer,Integer> s2 = null;
441 >        final Map<Integer,Integer> s2;
442          try {
443 <            s2 = (Map<Integer,Integer>) (s.getClass().newInstance());
443 >            s2 = (Map<Integer,Integer>)
444 >                s.getClass().getConstructor().newInstance();
445              s2.putAll(s);
446          }
447          catch (Exception e) { e.printStackTrace(); return; }
# Line 551 | Line 541 | public class IntMapCheck {
541              startTime = System.nanoTime();
542          }
543  
554
544          String classify() {
545              if (name.startsWith("Get"))
546                  return "Get                    ";
# Line 607 | Line 596 | public class IntMapCheck {
596  
597      static void shuffle(Integer[] keys) {
598          int size = keys.length;
599 <        for (int i=size; i>1; i--) {
599 >        for (int i = size; i > 1; i--) {
600              int r = rng.nextInt(i);
601              Integer t = keys[i-1];
602              keys[i-1] = keys[r];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines