Skip to content

Commit 41ed791

Browse files
[MOD] JUnit: XMark test code revised.
1 parent 14cede6 commit 41ed791

File tree

1 file changed

+41
-24
lines changed

1 file changed

+41
-24
lines changed

basex-tests/src/test/java/org/basex/performance/XMarkTest.java

+41-24
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.basex.core.Text.*;
44

55
import java.io.*;
6+
import java.math.*;
67

78
import org.basex.*;
89
import org.basex.api.client.*;
@@ -11,6 +12,7 @@
1112
import org.basex.core.users.*;
1213
import org.basex.io.*;
1314
import org.basex.util.*;
15+
import org.basex.util.list.*;
1416
import org.junit.*;
1517
import org.junit.Test;
1618

@@ -23,8 +25,14 @@
2325
public final class XMarkTest {
2426
/** Name of database. */
2527
private static final String DB = "111mb";
26-
/** Number of runs. */
27-
private static final int FACTOR = 1;
28+
29+
/** Test directory. */
30+
private static final IOFile DIR = new IOFile(Prop.TMP, "XMark");
31+
/** Output file. */
32+
private static final IOFile FILE = new IOFile(DIR, "master- " + DB + ".graph");
33+
34+
/** Maximum time per query (ms). */
35+
private static final int MAX = 2000;
2836

2937
/** Queries. */
3038
private static final String[] QUERIES = {
@@ -101,11 +109,8 @@ public final class XMarkTest {
101109
+ "count( for $p in $auction/site/people/person where empty($p/profile/@income) return $p ) } "
102110
+ "</na> </result>"
103111
};
104-
/** Queries to exclude. Negative value: do not consider global factor. */
105-
private static final int[] RUNS = {
106-
200, 70, 40, 60, 130, 22, 12, 0, 0, 0,
107-
0, 0, 27, 6, 170, 200, 90, 70, 12, 50
108-
};
112+
/** Queries to exclude. */
113+
private static final IntList EXCLUDE = new IntList().add(8, 9, 10, 11, 12);
109114

110115
/** Server flag. */
111116
private static BaseXServer server;
@@ -143,40 +148,52 @@ public static void close() throws Exception {
143148
*/
144149
@Test
145150
public void test() throws Exception {
146-
final TokenBuilder tb = new TokenBuilder();
147-
tb.add(DB + " (" + FACTOR + "x)").add(Prop.NL);
151+
final TokenBuilder tb = new TokenBuilder().add(DB).add(Prop.NL);
148152

149153
try(final ClientSession cs = createClient()) {
150154
cs.execute(new Open(DB));
151155

152156
// ignore first run
153-
System.out.println("Test runs...");
157+
System.out.println("Warming up...");
154158
for(int i = 1; i <= 20; i++) {
155-
if(RUNS[i - 1] > 0) {
156-
try(final ClientQuery cq = cs.query(QUERIES[i - 1])) { cq.execute(); }
159+
if(!EXCLUDE.contains(i)) {
160+
try(final ClientQuery cq = cs.query(QUERIES[i - 1])) {
161+
final Performance p = new Performance();
162+
cq.execute();
163+
System.out.println(i + ": " + p);
164+
}
157165
}
158166
}
159167

160-
System.out.println("Real runs...");
161-
final Performance p = new Performance();
168+
System.out.println(Prop.NL + "Testing...");
162169
for(int i = 1; i <= 20; i++) {
163170
tb.add(String.format("%02d", i)).add(" ");
171+
final BigDecimal max = BigDecimal.valueOf(MAX);
164172
try(final ClientQuery cq = cs.query(QUERIES[i - 1])) {
165-
final int run = RUNS[i - 1];
166-
final int runs = run < 0 ? -run : FACTOR * RUNS[i - 1];
167-
for(int r = 0; r < runs; r++) cq.execute();
168-
final String time = p.getTime(runs).replaceAll(" .*", "");
169-
System.out.println(i + ": " + runs * Double.parseDouble(time));
170-
tb.add(time);
173+
if(EXCLUDE.contains(i)) {
174+
tb.add("1000000");
175+
} else {
176+
double min = Double.MAX_VALUE;
177+
BigDecimal total = BigDecimal.valueOf(0);
178+
int r = 0;
179+
while(total.compareTo(max) < 0) {
180+
final Performance p = new Performance();
181+
cq.execute();
182+
final double t = Double.parseDouble(p.getTime().replaceAll(" .*", ""));
183+
total = total.add(BigDecimal.valueOf(t));
184+
min = Math.min(min, t);
185+
r++;
186+
}
187+
tb.add(Double.toString(min));
188+
System.out.println(i + ": " + min + " (" + r + " runs, stopped at " + total + " ms)");
189+
}
171190
}
172191
tb.add(Prop.NL);
173192
}
174193
}
175194

176-
System.out.println(tb);
177-
final IOFile file = new IOFile(Prop.TMP, "XMark");
178-
file.md();
179-
new IOFile(file, DB + "-" + FACTOR + ".graph").write(tb.finish());
195+
DIR.md();
196+
FILE.write(tb.finish());
180197
}
181198

182199
/**

0 commit comments

Comments
 (0)