"' options='" + options + "' when='" + when + "'>");
for (int f=0; f<tests.length; f++) {
File file = new File(dir + tests[f]);
Configuration config = (saproduct ? new EnterpriseConfiguration() : new Configuration());
if (lazy) {
config.setLazyConstructionMode(true);
}
if (satests) {
config.setSchemaValidationMode(Validation.STRICT);
config.addSchemaSource(new StreamSource(new File(dir + "schema.xsd")),
config.getErrorListener());
config.setConfigurationProperty(FeatureKeys.USE_TYPED_VALUE_CACHE, "false");
}
if (val) {
config.loadSchema(new File(dir + "sa\\schema.xsd").toURI().toString());
config.setSchemaValidationMode(Validation.STRICT);
}
Source streamSource = new StreamSource(file);
long pstart = System.currentTimeMillis();
DocumentInfo doc = config.buildDocument(streamSource);
long pend = System.currentTimeMillis();
System.out.println(" <file name='" + tests[f] +
"' size='" + file.length() +
"' build-time='" + (pend-pstart) + "'>");
Properties props = new Properties();
props.setProperty("method", "xml");
props.setProperty("indent", "yes");
if (runCompiled) {
for (int q=1; q<=20; q++) {
if (test != -1 && test != q) {
continue;
}
try {
ClassLoader usercodeLoader = new URLClassLoader(
new URL[]{new URL("file:///e:/javalib/xMark/java/")});
Class userClass = usercodeLoader.loadClass("Q" + q);
CompiledUserQuery cuq = (CompiledUserQuery) userClass.newInstance();
cuq.setConfiguration(config);
final DynamicQueryContext dqc = new DynamicQueryContext(config);
cuq.setDynamicContext(dqc);
int runs = 0;
long totalTime = 0;
long min = Integer.MAX_VALUE;
long max = 0;
if (checkResults && f==0) {
dqc.setContextItem(doc);
File out = new File("e:/javalib/xmark/output/q" + q + ".out");
//out.mkdirs();
OutputStream os = new FileOutputStream(out);
Result result = new StreamResult(os);
cuq.run(result, props);
os.close();
compare(new File("e:/javalib/xmark/output/q" + q + ".out"),
new File("e:/javalib/xmark/gold1m/q" + q + ".out"));
}
for (int t=0; t<1000; t++) {
dqc.setContextItem(doc);
Result result = new Sink();
long start, end;
start = System.currentTimeMillis();
cuq.run(result, props);
end = System.currentTimeMillis();
runs++;
long time = (end - start);
if (time < min) min = time;
if (time > max) max = time;
totalTime += time;
if (totalTime > 30000 && t>=2) break;
}
double avg = ((double)totalTime) / runs;
String avgs = format.format(avg);
System.out.println(" <query q='" + q +
"' avg='" + avgs +
"' runs='" + runs +
"' min='" + min +
"' max='" + max + "'/>");
} catch (XPathException err) {
System.err.println("Error in test " + q);
System.err.println(err.getMessageAndLocation());
}
}
} else {
for (int q=1; q<=20; q++) {
if (test != -1 && test != q) {
continue;
}
try {
File query = new File(dir + 'q' + q + ".xq");
StaticQueryContext qenv = config.newStaticQueryContext();
qenv.setBaseURI(query.toURI().toString());
if (val) {
qenv.getExecutable().setSchemaAware(true);
}
XQueryExpression exp = qenv.compileQuery(new FileReader(query));