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; |
34 |
|
} |
35 |
|
} |
36 |
|
|
37 |
– |
|
37 |
|
if (args.length > 1) |
38 |
|
numTests = Integer.parseInt(args[1]); |
39 |
|
|
67 |
|
|
68 |
|
TestTimer.printStats(); |
69 |
|
|
71 |
– |
|
70 |
|
if (doSerializeTest) |
71 |
|
stest(newMap(mapClass), size); |
72 |
|
} |
73 |
|
|
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(); |
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); |
185 |
|
reallyAssert(sum == expect); |
186 |
|
} |
187 |
|
|
193 |
– |
|
188 |
|
static void t9(Map<Integer,Integer> s) { |
189 |
|
int sum = 0; |
190 |
|
int iters = 20; |
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(); |
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); |
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); |
311 |
|
reallyAssert(sum == size); |
312 |
|
} |
313 |
|
|
323 |
– |
|
314 |
|
static void entest3(Hashtable ht, int size) { |
315 |
|
int sum = 0; |
316 |
|
|
389 |
|
reallyAssert(s.equals(m)); |
390 |
|
} |
391 |
|
|
402 |
– |
|
392 |
|
static void test(Map<Integer,Integer> s, Integer[] key) { |
393 |
|
int size = key.length; |
394 |
|
|
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; } |
541 |
|
startTime = System.nanoTime(); |
542 |
|
} |
543 |
|
|
554 |
– |
|
544 |
|
String classify() { |
545 |
|
if (name.startsWith("Get")) |
546 |
|
return "Get "; |