9 |
|
public class MapWordLoops { |
10 |
|
|
11 |
|
static final String[] WORDS_FILES = { |
12 |
< |
"kw.txt", |
12 |
> |
"kw.txt", |
13 |
|
"class.txt", |
14 |
|
"dir.txt", |
15 |
< |
"ids.txt", |
15 |
> |
"ids.txt", |
16 |
|
"testwords.txt", |
17 |
< |
// "/usr/dict/words", |
17 |
> |
// "/usr/dict/words", |
18 |
|
}; |
19 |
|
|
20 |
|
static final int MAX_WORDS = 500000; |
34 |
|
|
35 |
|
System.out.println("Testing " + mapClass.getName()); |
36 |
|
|
37 |
< |
for (int s = 0; s < WORDS_FILES.length; ++s) |
37 |
> |
for (int s = 0; s < WORDS_FILES.length; ++s) |
38 |
|
tests(mapClass, numTests, s); |
39 |
|
|
40 |
< |
for (int s = WORDS_FILES.length-1; s >= 0; --s) |
40 |
> |
for (int s = WORDS_FILES.length-1; s >= 0; --s) |
41 |
|
tests(mapClass, numTests, s); |
42 |
|
|
43 |
|
} |
44 |
|
|
45 |
|
static void tests(Class mapClass, int numTests, int sizeIndex) { |
46 |
< |
try { |
46 |
> |
try { |
47 |
|
String[] key = readWords(sizeIndex); |
48 |
|
int size = key.length; |
49 |
< |
|
49 |
> |
|
50 |
|
System.out.print("n = " +LoopHelpers.rightJustify(size) +" : "); |
51 |
|
long least = Long.MAX_VALUE; |
52 |
< |
|
52 |
> |
|
53 |
|
for (int i = 0; i < numTests; ++i) { |
54 |
|
Map<String,String> m = newMap(mapClass); |
55 |
|
long t = doTest(i, mapClass.getName(), m, key); |
57 |
|
m.clear(); |
58 |
|
m = null; |
59 |
|
} |
60 |
< |
|
60 |
> |
|
61 |
|
long nano = Math.round(1000000.0 * (least) / NOPS); |
62 |
|
System.out.println(LoopHelpers.rightJustify(nano) + " ns per op"); |
63 |
|
} catch (IOException ignore) { |
107 |
|
} |
108 |
|
|
109 |
|
static long doTest(int id, String name, |
110 |
< |
final Map<String,String> m, |
110 |
> |
final Map<String,String> m, |
111 |
|
final String[] key) { |
112 |
|
|
113 |
|
// System.out.print(name + "\t"); |
117 |
|
long afterRun = System.currentTimeMillis(); |
118 |
|
long runTime = (afterRun - startTime); |
119 |
|
int np = runner.total; |
120 |
< |
if (runner.total == runner.hashCode()) |
120 |
> |
if (runner.total == runner.hashCode()) |
121 |
|
System.out.println("Useless Number" + runner.total); |
122 |
|
int sz = runner.maxsz; |
123 |
< |
if (sz == runner.hashCode()) |
123 |
> |
if (sz == runner.hashCode()) |
124 |
|
System.out.println("Useless Number" + sz); |
125 |
|
// System.out.print(" m = " + sz); |
126 |
|
return runTime; |
141 |
|
int maxsz; |
142 |
|
|
143 |
|
Runner(int id, Map<String,String> m, String[] k) { |
144 |
< |
map = m; key = k; |
144 |
> |
map = m; key = k; |
145 |
|
pctrem = (int)(((long)premove * (long)(Integer.MAX_VALUE/2)) / 50); |
146 |
|
pctins = (int)(((long)pinsert * (long)(Integer.MAX_VALUE/2)) / 50); |
147 |
|
rng = new LoopHelpers.SimpleRandom((id + 1) * 8862213513L); |
153 |
|
int r = rng.next() & 0x7FFFFFFF; |
154 |
|
int jinc = (r & 7); |
155 |
|
j += jinc - 3; |
156 |
< |
if (j >= n) j -= n; |
156 |
> |
if (j >= n) j -= n; |
157 |
|
if (j < 0) j += n; |
158 |
|
|
159 |
|
int l = n / 4 + j; |
160 |
< |
if (l >= n) l -= n; |
161 |
< |
|
160 |
> |
if (l >= n) l -= n; |
161 |
> |
|
162 |
|
String k = key[j]; |
163 |
|
String x = map.get(k); |
164 |
< |
|
164 |
> |
|
165 |
|
if (x == null) { |
166 |
|
++nagets; |
167 |
|
if (r < pctins) { |