7 |
|
* @test |
8 |
|
* @synopsis Times and checks basic set operations |
9 |
|
*/ |
10 |
– |
import java.util.*; |
10 |
|
import java.io.*; |
11 |
+ |
import java.util.*; |
12 |
|
|
13 |
|
public class NavigableSetCheck { |
14 |
|
|
25 |
|
} |
26 |
|
|
27 |
|
public static void main(String[] args) throws Exception { |
28 |
< |
Class setClass = null; |
28 |
> |
Class<?> setClass = null; |
29 |
|
int numTests = 50; |
30 |
|
int size = 50000; |
31 |
|
|
37 |
|
} |
38 |
|
} |
39 |
|
|
40 |
– |
|
40 |
|
if (args.length > 1) |
41 |
|
numTests = Integer.parseInt(args[1]); |
42 |
|
|
45 |
|
|
46 |
|
System.out.println("Testing " + setClass.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(newSet(setClass), key); |
62 |
|
} |
63 |
|
|
64 |
|
TestTimer.printStats(); |
68 |
– |
|
65 |
|
} |
66 |
|
|
67 |
< |
static NavigableSet newSet(Class cl) { |
67 |
> |
static NavigableSet newSet(Class<?> cl) { |
68 |
|
try { |
69 |
|
NavigableSet m = (NavigableSet) cl.newInstance(); |
70 |
|
return m; |
73 |
|
} |
74 |
|
} |
75 |
|
|
80 |
– |
|
76 |
|
static void runTest(NavigableSet s, Integer[] key) { |
77 |
|
shuffle(key); |
78 |
|
int size = key.length; |
166 |
|
reallyAssert(sum == expect); |
167 |
|
} |
168 |
|
|
174 |
– |
|
169 |
|
static void higherTest(NavigableSet s) { |
170 |
|
int sum = 0; |
171 |
|
int iters = s.size(); |
220 |
|
reallyAssert(sum == iters-1); |
221 |
|
} |
222 |
|
|
229 |
– |
|
223 |
|
static void ktest(NavigableSet s, int size, Integer[] key) { |
224 |
|
timer.start("Contains ", size); |
225 |
|
int sum = 0; |
230 |
|
reallyAssert(sum == size); |
231 |
|
} |
232 |
|
|
240 |
– |
|
233 |
|
static void ittest1(NavigableSet s, int size) { |
234 |
|
int sum = 0; |
235 |
|
timer.start("Iter Key ", size); |
260 |
|
rittest1(s, size); |
261 |
|
} |
262 |
|
|
271 |
– |
|
263 |
|
static void rtest(NavigableSet s, int size) { |
264 |
|
timer.start("Remove (iterator) ", size); |
265 |
|
for (Iterator it = s.iterator(); it.hasNext(); ) { |
269 |
|
timer.finish(); |
270 |
|
} |
271 |
|
|
281 |
– |
|
282 |
– |
|
272 |
|
static void dtest(NavigableSet s, int size, Integer[] key) { |
273 |
|
timer.start("Add (addAll) ", size * 2); |
274 |
|
NavigableSet s2 = null; |
318 |
|
reallyAssert(s2.isEmpty() && s.isEmpty()); |
319 |
|
} |
320 |
|
|
332 |
– |
|
333 |
– |
|
321 |
|
static void test(NavigableSet s, Integer[] key) { |
322 |
|
int size = key.length; |
323 |
|
|
378 |
|
startTime = System.currentTimeMillis(); |
379 |
|
} |
380 |
|
|
394 |
– |
|
381 |
|
String classify() { |
382 |
|
if (name.startsWith("Contains")) |
383 |
|
return "Contains "; |