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; |
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 |
|
|
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) { |
74 |
> |
static Map<Integer,Integer> newMap(Class<?> cl) { |
75 |
|
try { |
76 |
|
Map m = (Map<Integer,Integer>)cl.newInstance(); |
77 |
|
return m; |
80 |
|
} |
81 |
|
} |
82 |
|
|
85 |
– |
|
83 |
|
static void runTest(Map<Integer,Integer> s, Integer[] key) { |
84 |
|
int size = key.length; |
85 |
|
long startTime = System.nanoTime(); |
112 |
|
reallyAssert(sum == expect * iters); |
113 |
|
} |
114 |
|
|
118 |
– |
|
115 |
|
static void t2(String nm, int n, Map<Integer,Integer> s, Integer[] key, int expect) { |
116 |
|
int sum = 0; |
117 |
|
timer.start(nm, n); |
186 |
|
reallyAssert(sum == expect); |
187 |
|
} |
188 |
|
|
193 |
– |
|
189 |
|
static void t9(Map<Integer,Integer> s) { |
190 |
|
int sum = 0; |
191 |
|
int iters = 20; |
197 |
|
reallyAssert(sum != 0); |
198 |
|
} |
199 |
|
|
205 |
– |
|
200 |
|
static void ktest(Map<Integer,Integer> s, int size, Integer[] key) { |
201 |
|
timer.start("ContainsKey ", size); |
202 |
|
Set ks = s.keySet(); |
208 |
|
reallyAssert(sum == size); |
209 |
|
} |
210 |
|
|
217 |
– |
|
211 |
|
static void ittest1(Map<Integer,Integer> s, int size) { |
212 |
|
int sum = 0; |
213 |
|
timer.start("Iter Key ", size); |
279 |
|
reallyAssert(s.size() == size); |
280 |
|
} |
281 |
|
|
289 |
– |
|
282 |
|
static void ittest(Map<Integer,Integer> s, int size) { |
283 |
|
for (int i = 0; i < 4; ++i) { |
284 |
|
ittest1(s, size); |
312 |
|
reallyAssert(sum == size); |
313 |
|
} |
314 |
|
|
323 |
– |
|
315 |
|
static void entest3(Hashtable ht, int size) { |
316 |
|
int sum = 0; |
317 |
|
|
390 |
|
reallyAssert(s.equals(m)); |
391 |
|
} |
392 |
|
|
402 |
– |
|
393 |
|
static void test(Map<Integer,Integer> s, Integer[] key) { |
394 |
|
int size = key.length; |
395 |
|
|
541 |
|
startTime = System.nanoTime(); |
542 |
|
} |
543 |
|
|
554 |
– |
|
544 |
|
String classify() { |
545 |
|
if (name.startsWith("Get")) |
546 |
|
return "Get "; |
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]; |