|
import java.io.File;
|
|
import java.io.StringReader;
|
|
import java.util.ArrayList;
|
|
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
|
import javax.xml.transform.Source;
|
|
import javax.xml.transform.Templates;
|
|
import javax.xml.transform.Transformer;
|
|
import javax.xml.transform.TransformerException;
|
|
import javax.xml.transform.TransformerFactory;
|
|
import javax.xml.transform.TransformerFactoryConfigurationError;
|
|
import javax.xml.transform.dom.DOMResult;
|
|
import javax.xml.transform.sax.SAXSource;
|
|
import javax.xml.transform.stream.StreamResult;
|
|
import javax.xml.transform.stream.StreamSource;
|
|
|
|
import org.xml.sax.InputSource;
|
|
|
|
import net.sf.saxon.lib.FeatureKeys;
|
|
//import net.sf.saxon.FeatureKeys;
|
|
|
|
public class SaxonOldTests {
|
|
|
|
public static final java.lang.String ALLOW_MULTITHREADING = "http://saxon.sf.net/feature/allow-multithreading";
|
|
|
|
public static final int THREADS=1;
|
|
public static final int ITERATIONS=20;
|
|
public static final int WARMUP=5;
|
|
public static void main(String[] args) throws InterruptedException {
|
|
|
|
String xslFilePath = args[0];
|
|
String xmlFilePath = args[1];
|
|
|
|
ArrayList<Thread> arrThreads = new ArrayList<Thread>();
|
|
|
|
long start = System.currentTimeMillis();
|
|
int threadCount = THREADS;
|
|
|
|
System.out.println("SAXON parallel threads per test: "+ threadCount);
|
|
|
|
/*System.out.println("OLD SAXON Iterations per test: "+ iterations);
|
|
System.out.println("Running transformLikeSonic (no threading)");
|
|
for (int i = 0; i < iterations; i++) {
|
|
//if(i==1) start = System.currentTimeMillis();
|
|
transformLikeSonic(xslFilePath, xmlFilePath,Boolean.FALSE);
|
|
}
|
|
*/
|
|
for (int i = 0; i < threadCount; i++)
|
|
{
|
|
Thread T1 = new Thread(new XslThread(xslFilePath, xmlFilePath,Boolean.FALSE));
|
|
T1.start();
|
|
arrThreads.add(T1);
|
|
}
|
|
|
|
for (int i = 0; i < arrThreads.size(); i++)
|
|
{
|
|
arrThreads.get(i).join();
|
|
}
|
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
System.out.println("processing avg: " + ((end-start)/threadCount)+"ms" );
|
|
}
|
|
|
|
|
|
|
|
}
|
|
class XslThread implements Runnable{
|
|
|
|
String m_xslFilePath;
|
|
String m_xmlFilePath;
|
|
Boolean m_allowThreads;
|
|
|
|
public XslThread(String xslFilePath, String xmlFilePath, Boolean allowThreads) {
|
|
|
|
m_xslFilePath=xslFilePath;
|
|
m_xmlFilePath=xmlFilePath;
|
|
m_allowThreads=allowThreads;
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
/*for (int i = 0; i < 100; i++)
|
|
{
|
|
transformLikeSonic(m_xslFilePath, m_xmlFilePath, m_allowThreads);
|
|
}*/
|
|
|
|
int iterations = SaxonOldTests.ITERATIONS;
|
|
int warmup = SaxonOldTests.WARMUP;
|
|
|
|
long start = 0;
|
|
for (int i = 0; i < (iterations + warmup); i++) {
|
|
if (i == warmup) {
|
|
start = System.currentTimeMillis();
|
|
}
|
|
|
|
long startSingle = System.currentTimeMillis();
|
|
|
|
transformLikeSonic(m_xslFilePath, m_xmlFilePath, m_allowThreads);
|
|
|
|
long endSingle = System.currentTimeMillis();
|
|
// System.out.println(i+ " processing took: " + (endSingle-startSingle)+"ms" );
|
|
}
|
|
|
|
long end = System.currentTimeMillis();
|
|
System.out.println("\n\nsingle thread processing avg: " + ((end - start) / iterations) + "ms");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
private void transformLikeSonic(String xslFilePath, String xmlFilePath, boolean allowThreads)
|
|
throws TransformerFactoryConfigurationError {
|
|
TransformerFactory factory = net.sf.saxon.TransformerFactoryImpl.newInstance();
|
|
|
|
factory.setAttribute(FeatureKeys.VERSION_WARNING, false);
|
|
factory.setAttribute(FeatureKeys.STRIP_WHITESPACE, "none");
|
|
|
|
factory.setAttribute(FeatureKeys.DTD_VALIDATION, Boolean.FALSE);
|
|
|
|
try {
|
|
//factory.setAttribute(ALLOW_MULTITHREADING, allowThreads);
|
|
}
|
|
catch(Exception e) {
|
|
|
|
}
|
|
|
|
|
|
Source xslSource = new StreamSource(new File(xslFilePath));
|
|
Source xmlSource = new StreamSource(new File(xmlFilePath));
|
|
Transformer transformer;
|
|
try {
|
|
transformer = factory.newTransformer(xslSource);
|
|
transformer.transform(xmlSource, new DOMResult());
|
|
|
|
} catch (TransformerException e) {
|
|
System.out.println(e.getMessage());
|
|
}
|
|
}
|
|
|
|
/*
|
|
* m_src = new SAXSource(m_parser,
|
|
new InputSource(new StringReader(((String)content))));
|
|
new StreamResult(out)
|
|
|
|
|
|
|
|
private Templates getTemplates()
|
|
|
|
use xerces as parser, source in and stream out, templates,
|
|
*/
|
|
}
|
|
|