Example 9-13: Simple utility to measure stylesheet performance

import oracle.xml.parser.v2.*;
import java.io.*;
// Quick and Dirty XSLT Processor Benchmarking Test
public class BenchmarkXSLT {
  // Assume 1st arg is name of XML File, 2nd arg is name of XSLT Stylesheet
  public static void main(String[] arg) throws Exception {
    // Open FileReaders on the XML Source and XSLT Stylesheet
    FileReader    xmlfile      = new FileReader(arg[0]);
    FileReader    xslfile      = new FileReader(arg[1]);
    // Create an XML Parser to parse both documents
    DOMParser     parser       = new DOMParser();
    // Parse and get the XML source for the transformation
    parser.parse(xmlfile);
    XMLDocument   xmlSource    = (XMLDocument) parser.getDocument();
    // Parse and get the XSL stylesheet source for the transformation
    parser.parse(xslfile);
    XMLDocument   xslSource    = (XMLDocument) parser.getDocument();
    // Construct an XSLStylesheet object from the XSL Source
    XSLStylesheet xslTransform = new XSLStylesheet(xslSource, /*baseurl*/null);
    // Create an XSLT Processor
    XSLProcessor  processor    = new XSLProcessor();
    long sumOfFiveTries = 0;
    for (int z = 1; z <= 5; z++) {
      long start = System.currentTimeMillis();
      // Do the transformation, ignoring the DocumentFragment return
      processor.processXSL(xslTransform,xmlSource);
      long time  = System.currentTimeMillis() - start;
      System.out.println("Run " + z + " = " + time + " msecs.");
      sumOfFiveTries += time;
    }
    long avg = sumOfFiveTries / 5;
    System.out.println("Five Run average time: " + avg + " msecs.");
  }
}