35 |
|
} |
36 |
|
|
37 |
|
|
38 |
< |
if (args.length > 1) |
38 |
> |
if (args.length > 1) |
39 |
|
numTests = Integer.parseInt(args[1]); |
40 |
|
|
41 |
< |
if (args.length > 2) |
41 |
> |
if (args.length > 2) |
42 |
|
size = Integer.parseInt(args[2]); |
43 |
|
|
44 |
|
boolean doSerializeTest = args.length > 3; |
49 |
|
while (absentSize < size) absentSize <<= 1; |
50 |
|
absentMask = absentSize-1; |
51 |
|
absent = new Integer[absentSize]; |
52 |
< |
for (int i = 0; i < absentSize/2; ++i) |
52 |
> |
for (int i = 0; i < absentSize/2; ++i) |
53 |
|
absent[i] = Integer.valueOf(-i - 1); |
54 |
< |
for (int i = absentSize/2; i < absentSize; ++i) |
54 |
> |
for (int i = absentSize/2; i < absentSize; ++i) |
55 |
|
absent[i] = Integer.valueOf(size + i + 1); |
56 |
|
|
57 |
|
Integer[] key = new Integer[size]; |
58 |
< |
for (int i = 0; i < size; ++i) |
58 |
> |
for (int i = 0; i < size; ++i) |
59 |
|
key[i] = Integer.valueOf(i); |
60 |
|
|
61 |
|
for (int rep = 0; rep < numTests; ++rep) { |
98 |
|
if (s.get(key[i]) != null) ++sum; |
99 |
|
} |
100 |
|
} |
101 |
< |
timer.finish(); |
101 |
> |
timer.finish(); |
102 |
|
reallyAssert (sum == expect * iters); |
103 |
|
} |
104 |
|
|
111 |
|
if ((Integer)(s.get(i)) != i) ++sum; |
112 |
|
} |
113 |
|
} |
114 |
< |
timer.finish(); |
114 |
> |
timer.finish(); |
115 |
|
reallyAssert (sum == expect * iters); |
116 |
|
} |
117 |
|
|
122 |
|
for (int i = 0; i < n; i++) { |
123 |
|
if (s.remove(key[i]) != null) ++sum; |
124 |
|
} |
125 |
< |
timer.finish(); |
125 |
> |
timer.finish(); |
126 |
|
reallyAssert (sum == expect); |
127 |
|
} |
128 |
|
|
134 |
|
Integer v = absent[i & absentMask]; |
135 |
|
if (s.put(k, v) == null) ++sum; |
136 |
|
} |
137 |
< |
timer.finish(); |
137 |
> |
timer.finish(); |
138 |
|
reallyAssert (sum == expect); |
139 |
|
} |
140 |
|
|
144 |
|
for (int i = 0; i < n; i++) { |
145 |
|
if (s.containsKey(key[i])) ++sum; |
146 |
|
} |
147 |
< |
timer.finish(); |
147 |
> |
timer.finish(); |
148 |
|
reallyAssert (sum == expect); |
149 |
|
} |
150 |
|
|
154 |
|
for (int i = n-2; i >= 0; i-=2) { |
155 |
|
if (s.remove(key[i]) != null) ++sum; |
156 |
|
} |
157 |
< |
timer.finish(); |
157 |
> |
timer.finish(); |
158 |
|
reallyAssert (sum == expect); |
159 |
|
} |
160 |
|
|
165 |
|
if (s.get(k1[i]) != null) ++sum; |
166 |
|
if (s.get(k2[i & absentMask]) != null) ++sum; |
167 |
|
} |
168 |
< |
timer.finish(); |
168 |
> |
timer.finish(); |
169 |
|
reallyAssert (sum == n); |
170 |
|
} |
171 |
|
|
176 |
|
if (s.containsKey(k1[i])) ++sum; |
177 |
|
if (s.containsKey(k2[i & absentMask])) ++sum; |
178 |
|
} |
179 |
< |
timer.finish(); |
179 |
> |
timer.finish(); |
180 |
|
reallyAssert (sum == n); |
181 |
|
} |
182 |
|
|
186 |
|
for (int i = 0; i < n; i++) { |
187 |
|
if (s.get(key[i]) != null) ++sum; |
188 |
|
} |
189 |
< |
timer.finish(); |
189 |
> |
timer.finish(); |
190 |
|
reallyAssert (sum == expect); |
191 |
|
} |
192 |
|
|
198 |
|
int step = absentSize / iters; |
199 |
|
for (int i = 0; i < absentSize; i += step) |
200 |
|
if (s.containsValue(absent[i])) ++sum; |
201 |
< |
timer.finish(); |
201 |
> |
timer.finish(); |
202 |
|
reallyAssert (sum != 0); |
203 |
|
} |
204 |
|
|
210 |
|
for (int i = 0; i < size; i++) { |
211 |
|
if (ks.contains(key[i])) ++sum; |
212 |
|
} |
213 |
< |
timer.finish(); |
213 |
> |
timer.finish(); |
214 |
|
reallyAssert (sum == size); |
215 |
|
} |
216 |
|
|
222 |
|
if(it.next() != MISSING) |
223 |
|
++sum; |
224 |
|
} |
225 |
< |
timer.finish(); |
226 |
< |
// if (sum != size) |
225 |
> |
timer.finish(); |
226 |
> |
// if (sum != size) |
227 |
|
// System.out.println("iters " + sum + " size " + size); |
228 |
|
reallyAssert (sum == size); |
229 |
|
} |
235 |
|
if(it.next() != MISSING) |
236 |
|
++sum; |
237 |
|
} |
238 |
< |
timer.finish(); |
239 |
< |
// if (sum != size) |
238 |
> |
timer.finish(); |
239 |
> |
// if (sum != size) |
240 |
|
// System.out.println("iters " + sum + " size " + size); |
241 |
|
reallyAssert (sum == size); |
242 |
|
} |
247 |
|
if(it.next() != MISSING) |
248 |
|
++sum; |
249 |
|
} |
250 |
< |
timer.finish(); |
250 |
> |
timer.finish(); |
251 |
|
reallyAssert (sum == size); |
252 |
|
} |
253 |
|
|
256 |
|
reallyAssert (s.size() == size); |
257 |
|
int sum = 0; |
258 |
|
timer.start("Iter XEntry ", size); |
259 |
< |
Iterator it = s.entrySet().iterator(); |
259 |
> |
Iterator it = s.entrySet().iterator(); |
260 |
|
Integer k = null; |
261 |
|
Integer v = null; |
262 |
|
for (int i = 0; i < size-pos; ++i) { |
281 |
|
reallyAssert (s.size() == size-1); |
282 |
|
s.put(k, v); |
283 |
|
reallyAssert (seen.size() == size); |
284 |
< |
timer.finish(); |
284 |
> |
timer.finish(); |
285 |
|
reallyAssert (sum == size); |
286 |
|
reallyAssert (s.size() == size); |
287 |
|
} |
293 |
|
ittest2(s, size); |
294 |
|
ittest3(s, size); |
295 |
|
} |
296 |
< |
// for (int i = 0; i < size-1; ++i) |
296 |
> |
// for (int i = 0; i < size-1; ++i) |
297 |
|
// ittest4(s, size, i); |
298 |
|
} |
299 |
|
|
305 |
|
if (en.nextElement() != MISSING) |
306 |
|
++sum; |
307 |
|
} |
308 |
< |
timer.finish(); |
308 |
> |
timer.finish(); |
309 |
|
reallyAssert (sum == size); |
310 |
|
} |
311 |
|
|
316 |
|
if (en.nextElement() != MISSING) |
317 |
|
++sum; |
318 |
|
} |
319 |
< |
timer.finish(); |
319 |
> |
timer.finish(); |
320 |
|
reallyAssert (sum == size); |
321 |
|
} |
322 |
|
|
325 |
|
int sum = 0; |
326 |
|
|
327 |
|
timer.start("Iterf Enumeration Key ", size); |
328 |
< |
Enumeration en = ht.keys(); |
328 |
> |
Enumeration en = ht.keys(); |
329 |
|
for (int i = 0; i < size; ++i) { |
330 |
|
if (en.nextElement() != MISSING) |
331 |
|
++sum; |
332 |
|
} |
333 |
< |
timer.finish(); |
333 |
> |
timer.finish(); |
334 |
|
reallyAssert (sum == size); |
335 |
|
} |
336 |
|
|
337 |
|
static void entest4(Hashtable ht, int size) { |
338 |
|
int sum = 0; |
339 |
|
timer.start("Iterf Enumeration Value", size); |
340 |
< |
Enumeration en = ht.elements(); |
340 |
> |
Enumeration en = ht.elements(); |
341 |
|
for (int i = 0; i < size; ++i) { |
342 |
|
if (en.nextElement() != MISSING) |
343 |
|
++sum; |
344 |
|
} |
345 |
< |
timer.finish(); |
345 |
> |
timer.finish(); |
346 |
|
reallyAssert (sum == size); |
347 |
|
} |
348 |
|
|
367 |
|
it.remove(); |
368 |
|
} |
369 |
|
reallyAssert(s.isEmpty()); |
370 |
< |
timer.finish(); |
370 |
> |
timer.finish(); |
371 |
|
} |
372 |
|
|
373 |
|
static void stest(Map<Integer,Integer> s, int size) throws Exception { |
374 |
< |
if (!(s instanceof Serializable)) |
374 |
> |
if (!(s instanceof Serializable)) |
375 |
|
return; |
376 |
|
System.out.print("Serialize : "); |
377 |
< |
|
377 |
> |
|
378 |
|
for (int i = 0; i < size; i++) { |
379 |
|
s.put(Integer.valueOf(i), Integer.valueOf(1)); |
380 |
|
} |
399 |
|
reallyAssert (s.equals(m)); |
400 |
|
} |
401 |
|
|
402 |
< |
|
402 |
> |
|
403 |
|
static void test(Map<Integer,Integer> s, Integer[] key) { |
404 |
|
int size = key.length; |
405 |
|
|
433 |
|
reallyAssert(s.size() == size); |
434 |
|
timer.start("Clear ", size); |
435 |
|
s.clear(); |
436 |
< |
timer.finish(); |
436 |
> |
timer.finish(); |
437 |
|
t1("Get (absent) ", size, s, key, 0, 1); |
438 |
|
t4("ContainsKey ", size, s, key, 0); |
439 |
|
t2("Remove (absent) ", size, s, key, 0); |
445 |
|
reallyAssert(s.size() == 0); |
446 |
|
timer.start("Clear ", size); |
447 |
|
s.clear(); |
448 |
< |
timer.finish(); |
448 |
> |
timer.finish(); |
449 |
|
t3("Put (presized) ", size, s, key, size); |
450 |
|
|
451 |
|
timer.start("Put (putAll) ", size * 2); |
455 |
|
s2.putAll(s); |
456 |
|
} |
457 |
|
catch (Exception e) { e.printStackTrace(); return; } |
458 |
< |
timer.finish(); |
459 |
< |
|
458 |
> |
timer.finish(); |
459 |
> |
|
460 |
|
timer.start("Iter Equals ", size * 2); |
461 |
|
boolean eqt = s2.equals(s) && s.equals(s2); |
462 |
|
reallyAssert (eqt); |
463 |
< |
timer.finish(); |
463 |
> |
timer.finish(); |
464 |
|
|
465 |
|
timer.start("Iter HashCode ", size * 2); |
466 |
|
int shc = s.hashCode(); |
467 |
|
int s2hc = s2.hashCode(); |
468 |
|
reallyAssert (shc == s2hc); |
469 |
< |
timer.finish(); |
469 |
> |
timer.finish(); |
470 |
|
|
471 |
|
timer.start("Put (present) ", size * 2); |
472 |
|
s2.putAll(s); |
473 |
< |
timer.finish(); |
473 |
> |
timer.finish(); |
474 |
|
|
475 |
|
timer.start("Put (present) ", size); |
476 |
|
int ipsum = 0; |
480 |
|
++ipsum; |
481 |
|
} |
482 |
|
reallyAssert (ipsum == s.size()); |
483 |
< |
timer.finish(); |
483 |
> |
timer.finish(); |
484 |
|
|
485 |
|
timer.start("Iter EntrySet contains ", size * 2); |
486 |
|
Set es2 = s2.entrySet(); |
489 |
|
Object entry = i1.next(); |
490 |
|
if (es2.contains(entry)) ++sum; |
491 |
|
} |
492 |
< |
timer.finish(); |
492 |
> |
timer.finish(); |
493 |
|
reallyAssert (sum == size); |
494 |
|
|
495 |
|
Integer hold = s2.get(key[size-1]); |
497 |
|
timer.start("Iter Equals ", size * 2); |
498 |
|
eqt = s2.equals(s) && s.equals(s2); |
499 |
|
reallyAssert (!eqt); |
500 |
< |
timer.finish(); |
500 |
> |
timer.finish(); |
501 |
|
|
502 |
|
timer.start("Iter HashCode ", size * 2); |
503 |
|
int s1h = s.hashCode(); |
504 |
|
int s2h = s2.hashCode(); |
505 |
|
reallyAssert (s1h != s2h); |
506 |
< |
timer.finish(); |
506 |
> |
timer.finish(); |
507 |
|
|
508 |
|
s2.put(key[size-1], hold); |
509 |
|
timer.start("Remove (present) ", size * 2); |
511 |
|
Set es = s.entrySet(); |
512 |
|
while (s2i.hasNext()) |
513 |
|
reallyAssert(es.remove(s2i.next())); |
514 |
< |
timer.finish(); |
514 |
> |
timer.finish(); |
515 |
|
|
516 |
|
reallyAssert (s.isEmpty()); |
517 |
|
|
518 |
|
timer.start("Clear ", size); |
519 |
|
s2.clear(); |
520 |
< |
timer.finish(); |
520 |
> |
timer.finish(); |
521 |
|
reallyAssert (s2.isEmpty() && s.isEmpty()); |
522 |
|
} |
523 |
|
|
528 |
|
private String cname; |
529 |
|
|
530 |
|
static final java.util.TreeMap accum = new java.util.TreeMap(); |
531 |
< |
|
531 |
> |
|
532 |
|
static void printStats() { |
533 |
|
for (Iterator it = accum.entrySet().iterator(); it.hasNext(); ) { |
534 |
|
Map.Entry e = (Map.Entry)(it.next()); |
535 |
|
Stats stats = ((Stats)(e.getValue())); |
536 |
|
long n = stats.number; |
537 |
|
double t; |
538 |
< |
if (n > 0) |
538 |
> |
if (n > 0) |
539 |
|
t = stats.sum / n; |
540 |
|
else |
541 |
|
t = stats.least; |
543 |
|
System.out.println(e.getKey() + ": " + nano); |
544 |
|
} |
545 |
|
} |
546 |
< |
|
546 |
> |
|
547 |
|
void start(String name, long numOps) { |
548 |
|
this.name = name; |
549 |
|
this.cname = classify(); |
550 |
|
this.numOps = numOps; |
551 |
|
startTime = System.nanoTime(); |
552 |
|
} |
553 |
< |
|
553 |
> |
|
554 |
|
|
555 |
|
String classify() { |
556 |
|
if (name.startsWith("Get")) |
561 |
|
return "Remove "; |
562 |
|
else if (name.startsWith("Iter")) |
563 |
|
return "Iter "; |
564 |
< |
else |
564 |
> |
else |
565 |
|
return null; |
566 |
|
} |
567 |
|
|
616 |
|
} |
617 |
|
|
618 |
|
} |
619 |
– |
|