4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
< |
|
8 |
< |
import java.util.*; |
9 |
< |
import java.util.concurrent.*; |
7 |
> |
import java.util.Collection; |
8 |
> |
import java.util.Random; |
9 |
> |
import java.util.concurrent.CyclicBarrier; |
10 |
> |
import java.util.concurrent.ExecutorService; |
11 |
> |
import java.util.concurrent.Executors; |
12 |
|
|
13 |
|
public class CollectionLoops { |
14 |
|
static int pinsert = 100; |
25 |
|
int nkeys = 10000; |
26 |
|
int nops = 100000; |
27 |
|
|
28 |
< |
Class collectionClass = null; |
28 |
> |
Class<?> collectionClass = null; |
29 |
|
if (args.length > 0) { |
30 |
|
try { |
31 |
|
collectionClass = Class.forName(args[0]); |
67 |
|
test(4, 100, 100, collectionClass); |
68 |
|
print = true; |
69 |
|
|
68 |
– |
int k = 1; |
70 |
|
int warmups = 2; |
71 |
< |
for (int i = 1; i <= maxThreads;) { |
71 |
> |
for (int k = 1, i = 1; i <= maxThreads;) { |
72 |
|
Thread.sleep(100); |
73 |
|
test(i, nkeys, nops, collectionClass); |
74 |
|
if (warmups > 0) |
105 |
|
} |
106 |
|
} |
107 |
|
|
108 |
< |
static void test(int i, int nk, int nops, Class collectionClass) throws Exception { |
108 |
> |
static void test(int i, int nk, int nops, Class<?> collectionClass) throws Exception { |
109 |
|
if (print) |
110 |
|
System.out.print("Threads: " + i + "\t:"); |
111 |
< |
Collection<Integer> collection = (Collection<Integer>)collectionClass.newInstance(); |
111 |
> |
Collection<Integer> collection = |
112 |
> |
(Collection<Integer>) collectionClass.getConstructor().newInstance(); |
113 |
|
Integer[] key = makeKeys(nk); |
114 |
|
// Uncomment to start with a non-empty table |
115 |
|
for (int j = 0; j < nk; j += 2) |
143 |
|
int total; |
144 |
|
int nops; |
145 |
|
|
146 |
< |
Runner(int id, Collection<Integer> collection, Integer[] key, CyclicBarrier barrier, int nops) { |
146 |
> |
Runner(int id, Collection<Integer> collection, Integer[] key, CyclicBarrier barrier, int nops) { |
147 |
|
this.collection = collection; |
148 |
|
this.key = key; |
149 |
|
this.barrier = barrier; |