|
3 | 3 | import static org.basex.core.Text.*;
|
4 | 4 |
|
5 | 5 | import java.io.*;
|
| 6 | +import java.math.*; |
6 | 7 |
|
7 | 8 | import org.basex.*;
|
8 | 9 | import org.basex.api.client.*;
|
|
11 | 12 | import org.basex.core.users.*;
|
12 | 13 | import org.basex.io.*;
|
13 | 14 | import org.basex.util.*;
|
| 15 | +import org.basex.util.list.*; |
14 | 16 | import org.junit.*;
|
15 | 17 | import org.junit.Test;
|
16 | 18 |
|
|
23 | 25 | public final class XMarkTest {
|
24 | 26 | /** Name of database. */
|
25 | 27 | 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; |
28 | 36 |
|
29 | 37 | /** Queries. */
|
30 | 38 | private static final String[] QUERIES = {
|
@@ -101,11 +109,8 @@ public final class XMarkTest {
|
101 | 109 | + "count( for $p in $auction/site/people/person where empty($p/profile/@income) return $p ) } "
|
102 | 110 | + "</na> </result>"
|
103 | 111 | };
|
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); |
109 | 114 |
|
110 | 115 | /** Server flag. */
|
111 | 116 | private static BaseXServer server;
|
@@ -143,40 +148,52 @@ public static void close() throws Exception {
|
143 | 148 | */
|
144 | 149 | @Test
|
145 | 150 | 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); |
148 | 152 |
|
149 | 153 | try(final ClientSession cs = createClient()) {
|
150 | 154 | cs.execute(new Open(DB));
|
151 | 155 |
|
152 | 156 | // ignore first run
|
153 |
| - System.out.println("Test runs..."); |
| 157 | + System.out.println("Warming up..."); |
154 | 158 | 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 | + } |
157 | 165 | }
|
158 | 166 | }
|
159 | 167 |
|
160 |
| - System.out.println("Real runs..."); |
161 |
| - final Performance p = new Performance(); |
| 168 | + System.out.println(Prop.NL + "Testing..."); |
162 | 169 | for(int i = 1; i <= 20; i++) {
|
163 | 170 | tb.add(String.format("%02d", i)).add(" ");
|
| 171 | + final BigDecimal max = BigDecimal.valueOf(MAX); |
164 | 172 | 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 | + } |
171 | 190 | }
|
172 | 191 | tb.add(Prop.NL);
|
173 | 192 | }
|
174 | 193 | }
|
175 | 194 |
|
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()); |
180 | 197 | }
|
181 | 198 |
|
182 | 199 | /**
|
|
0 commit comments