18 |
|
import java.util.concurrent.*; |
19 |
|
|
20 |
|
public class MapLoops { |
21 |
< |
static int nkeys = 10000; |
21 |
> |
static int nkeys = 1000; |
22 |
|
static int pinsert = 60; |
23 |
|
static int premove = 2; |
24 |
|
static int maxThreads = 100; |
25 |
< |
static int nops = 8000000; |
25 |
> |
static int nops = 1000000; |
26 |
|
static int removesPerMaxRandom; |
27 |
|
static int insertsPerMaxRandom; |
28 |
|
|
114 |
|
// Uncomment to start with a non-empty table |
115 |
|
// for (int j = 0; j < nkeys; j += 4) // start 1/4 occupied |
116 |
|
// map.put(key[j], key[j]); |
117 |
+ |
shuffleKeys(key); |
118 |
|
LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer(); |
119 |
|
CyclicBarrier barrier = new CyclicBarrier(i+1, timer); |
120 |
|
for (int t = 0; t < i; ++t) |
121 |
< |
pool.execute(new Runner(map, key, barrier)); |
121 |
> |
pool.execute(new Runner(t, map, key, barrier)); |
122 |
|
barrier.await(); |
123 |
|
barrier.await(); |
124 |
|
long time = timer.getTime(); |
132 |
|
static class Runner implements Runnable { |
133 |
|
final Map<Integer,Integer> map; |
134 |
|
final Integer[] key; |
135 |
< |
final LoopHelpers.SimpleRandom rng = new LoopHelpers.SimpleRandom(); |
135 |
> |
final LoopHelpers.SimpleRandom rng; |
136 |
|
final CyclicBarrier barrier; |
137 |
|
int position; |
138 |
|
int total; |
139 |
|
|
140 |
< |
Runner(Map<Integer,Integer> map, Integer[] key, CyclicBarrier barrier) { |
140 |
> |
Runner(int id, Map<Integer,Integer> map, Integer[] key, CyclicBarrier barrier) { |
141 |
|
this.map = map; |
142 |
|
this.key = key; |
143 |
|
this.barrier = barrier; |
144 |
< |
position = key.length / 2; |
144 |
> |
position = key.length / 2; |
145 |
> |
rng = new LoopHelpers.SimpleRandom((id + 1) * 8862213513L); |
146 |
> |
rng.next(); |
147 |
|
} |
148 |
|
|
149 |
|
int step() { |