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 |
|
|
37 |
|
} |
38 |
|
} |
39 |
|
|
40 |
– |
|
40 |
|
if (args.length > 1) |
41 |
|
numTests = Integer.parseInt(args[1]); |
42 |
|
|
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; |
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) { |
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; |
165 |
|
reallyAssert(sum == expect); |
166 |
|
} |
167 |
|
|
174 |
– |
|
168 |
|
static void t9(NavigableMap s) { |
169 |
|
int sum = 0; |
170 |
|
int iters = 20; |
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(); |
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); |
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(); ) { |
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; } |
379 |
|
reallyAssert(s2.isEmpty() && s.isEmpty()); |
380 |
|
} |
381 |
|
|
394 |
– |
|
395 |
– |
|
382 |
|
static void test(NavigableMap s, Integer[] key) { |
383 |
|
int size = key.length; |
384 |
|
|
440 |
|
startTime = System.currentTimeMillis(); |
441 |
|
} |
442 |
|
|
457 |
– |
|
443 |
|
String classify() { |
444 |
|
if (name.startsWith("Get")) |
445 |
|
return "Get "; |
479 |
|
if (timePerOp < stats.least) stats.least = timePerOp; |
480 |
|
} |
481 |
|
} |
497 |
– |
|
482 |
|
} |
499 |
– |
|
483 |
|
} |
484 |
|
|
485 |
|
static class Stats { |