}
);
// warmup hotspot VM
for (int i=0; i < 100; i++) {
new Builder(false);
new Builder(true);
pool.getW3CBuilder(map);
}
System.gc();
Thread.sleep(1000); // give hotspot some time to optimize
// run the benchmark
long start = System.currentTimeMillis();
for (int i = 0; i < numThreads; i++) { // stress gc on threads and ThreadLocal via container-like scenario
Thread thread = new Thread() {
int checksum = 0; // make dead-code elimination impossible for hotspot vm
public void run() {
try {
for (int i=0; i < runs; i++) { // user code inside multi-threaded container
bench();
}
} catch (Exception e) { throw new RuntimeException(e); }
}
private void bench() throws Exception {
Builder builder;
if (validate.equals("validateschema")) {
builder = pool.getW3CBuilder(map);
}
else {
builder = isPooled ?
pool.getBuilder(validate.equals("validate")) :
new Builder(validate.equals("validate"));
}
checksum += builder.hashCode();
if (! fileName.equals("nofile")) {
Document doc = memory ?
builder.build(new ByteArrayInputStream(bytes, 0, bytes.length)) :
builder.build(new FileInputStream(fileName));
//String str = doc.toXML();
//System.out.print('.');
checksum += doc.getChildCount();
}
}