9 |
|
public class CollectionWordLoops { |
10 |
|
|
11 |
|
static final String[] WORDS_FILES = { |
12 |
< |
"kw.txt", |
12 |
> |
"kw.txt", |
13 |
|
"class.txt", |
14 |
|
// "dir.txt", |
15 |
< |
// "ids.txt", |
16 |
< |
// "/usr/dict/words", |
15 |
> |
// "ids.txt", |
16 |
> |
// "/usr/dict/words", |
17 |
|
}; |
18 |
|
|
19 |
|
static final int MAX_WORDS = 500000; |
32 |
|
|
33 |
|
System.out.println("Testing " + collectionClass.getName()); |
34 |
|
|
35 |
< |
for (int s = 0; s < WORDS_FILES.length; ++s) |
35 |
> |
for (int s = 0; s < WORDS_FILES.length; ++s) |
36 |
|
tests(collectionClass, numTests, s); |
37 |
|
|
38 |
< |
for (int s = WORDS_FILES.length-1; s >= 0; --s) |
38 |
> |
for (int s = WORDS_FILES.length-1; s >= 0; --s) |
39 |
|
tests(collectionClass, numTests, s); |
40 |
|
|
41 |
|
} |
42 |
|
|
43 |
|
static void tests(Class collectionClass, int numTests, int sizeIndex) { |
44 |
< |
try { |
44 |
> |
try { |
45 |
|
String[] key = readWords(sizeIndex); |
46 |
|
int size = key.length; |
47 |
< |
|
47 |
> |
|
48 |
|
System.out.print("n = " +LoopHelpers.rightJustify(size) +" : "); |
49 |
|
long least = Long.MAX_VALUE; |
50 |
< |
|
50 |
> |
|
51 |
|
for (int i = 0; i < numTests; ++i) { |
52 |
|
Collection<String> m = newCollection(collectionClass); |
53 |
|
long t = doTest(collectionClass.getName(), m, key); |
55 |
|
m.clear(); |
56 |
|
m = null; |
57 |
|
} |
58 |
< |
|
58 |
> |
|
59 |
|
long nano = Math.round(1000000.0 * (least) / NOPS); |
60 |
|
System.out.println(LoopHelpers.rightJustify(nano) + " ns per op"); |
61 |
|
} catch (IOException ignore) { |
105 |
|
} |
106 |
|
|
107 |
|
static long doTest(String name, |
108 |
< |
final Collection<String> m, |
108 |
> |
final Collection<String> m, |
109 |
|
final String[] key) { |
110 |
|
|
111 |
|
// System.out.print(name + "\t"); |
115 |
|
long afterRun = System.currentTimeMillis(); |
116 |
|
long runTime = (afterRun - startTime); |
117 |
|
int np = runner.total; |
118 |
< |
if (runner.total == runner.hashCode()) |
118 |
> |
if (runner.total == runner.hashCode()) |
119 |
|
System.out.println("Useless Number" + runner.total); |
120 |
|
int sz = runner.maxsz; |
121 |
< |
if (sz == runner.hashCode()) |
121 |
> |
if (sz == runner.hashCode()) |
122 |
|
System.out.println("Useless Number" + sz); |
123 |
|
// System.out.print(" m = " + sz); |
124 |
|
return runTime; |
139 |
|
int maxsz; |
140 |
|
|
141 |
|
Runner(Collection<String> m, String[] k) { |
142 |
< |
collection = m; key = k; |
142 |
> |
collection = m; key = k; |
143 |
|
pctrem = (int)(((long)premove * (long)(Integer.MAX_VALUE/2)) / 50); |
144 |
|
pctins = (int)(((long)pinsert * (long)(Integer.MAX_VALUE/2)) / 50); |
145 |
|
} |
150 |
|
int r = rng.next() & 0x7FFFFFFF; |
151 |
|
int jinc = (r & 7); |
152 |
|
j += jinc - 3; |
153 |
< |
if (j >= n) j -= n; |
153 |
> |
if (j >= n) j -= n; |
154 |
|
if (j < 0) j += n; |
155 |
|
|
156 |
|
int l = n / 4 + j; |
157 |
< |
if (l >= n) l -= n; |
158 |
< |
|
157 |
> |
if (l >= n) l -= n; |
158 |
> |
|
159 |
|
String k = key[j]; |
160 |
< |
|
160 |
> |
|
161 |
|
if (!collection.contains(k)) { |
162 |
|
++nagets; |
163 |
|
if (r < pctins) { |