20 |
|
|
21 |
|
public static void main(String[] args) throws Exception { |
22 |
|
|
23 |
< |
Class mapClass = null; |
23 |
> |
Class<?> mapClass = null; |
24 |
|
if (args.length > 0) { |
25 |
|
try { |
26 |
|
mapClass = Class.forName(args[0]); |
46 |
|
if (args.length > 5) |
47 |
|
nops = Integer.parseInt(args[5]); |
48 |
|
|
49 |
+ |
if (nops < nkeys) |
50 |
+ |
nops = nkeys; |
51 |
+ |
|
52 |
|
// normalize probabilities wrt random number generator |
53 |
|
removesPerMaxRandom = (int)(((double)premove/100.0 * 0x7FFFFFFFL)); |
54 |
|
insertsPerMaxRandom = (int)(((double)pinsert/100.0 * 0x7FFFFFFFL)); |
62 |
|
System.out.println(); |
63 |
|
|
64 |
|
int warmups = 2; |
65 |
< |
for (int k = 1, i = 1; i <= maxThreads;) { |
66 |
< |
Thread.sleep(100); |
67 |
< |
test(i, nkeys, mapClass); |
68 |
< |
if (warmups > 0) |
69 |
< |
--warmups; |
70 |
< |
else if (i == k) { |
71 |
< |
k = i << 1; |
72 |
< |
i = i + (i >>> 1); |
73 |
< |
} |
74 |
< |
else if (i == 1 && k == 2) { |
75 |
< |
i = k; |
76 |
< |
warmups = 1; |
65 |
> |
for (int reps = 0; reps < 3; ++reps) { |
66 |
> |
int k = 1; |
67 |
> |
for (int i = 1; i <= maxThreads;) { |
68 |
> |
Thread.sleep(100); |
69 |
> |
test(i, nkeys, mapClass); |
70 |
> |
if (warmups > 0) |
71 |
> |
--warmups; |
72 |
> |
else if (i == k) { |
73 |
> |
k = i << 1; |
74 |
> |
i = i + (i >>> 1); |
75 |
> |
} |
76 |
> |
else if (i == 1 && k == 2) { |
77 |
> |
i = k; |
78 |
> |
warmups = 1; |
79 |
> |
} |
80 |
> |
else |
81 |
> |
i = k; |
82 |
|
} |
75 |
– |
else |
76 |
– |
i = k; |
83 |
|
} |
84 |
|
pool.shutdown(); |
85 |
|
} |
102 |
|
} |
103 |
|
} |
104 |
|
|
105 |
< |
static void test(int i, int nkeys, Class mapClass) throws Exception { |
105 |
> |
static void test(int i, int nkeys, Class<?> mapClass) throws Exception { |
106 |
|
System.out.print("Threads: " + i + "\t:"); |
107 |
< |
Map<Integer, Integer> map = (Map<Integer,Integer>)mapClass.newInstance(); |
107 |
> |
Map<Integer, Integer> map = |
108 |
> |
(Map<Integer,Integer>) mapClass.getConstructor().newInstance(); |
109 |
|
Integer[] key = makeKeys(nkeys); |
110 |
|
// Uncomment to start with a non-empty table |
111 |
|
// for (int j = 0; j < nkeys; j += 4) // start 1/4 occupied |
133 |
|
int position; |
134 |
|
int total; |
135 |
|
|
136 |
< |
Runner(int id, Map<Integer,Integer> map, Integer[] key, CyclicBarrier barrier) { |
136 |
> |
Runner(int id, Map<Integer,Integer> map, Integer[] key, CyclicBarrier barrier) { |
137 |
|
this.map = map; |
138 |
|
this.key = key; |
139 |
|
this.barrier = barrier; |
165 |
|
} |
166 |
|
else if (r < insertsPerMaxRandom) { |
167 |
|
++position; |
168 |
< |
map.put(k, k); |
168 |
> |
map.putIfAbsent(k, k); |
169 |
|
return 2; |
170 |
|
} |
171 |
|
|