1 30 package org.objectweb.asm.xml; 31 32 import java.io.BufferedInputStream ; 33 import java.io.File ; 34 import java.io.FileInputStream ; 35 import java.io.IOException ; 36 import java.io.InputStream ; 37 import java.io.OutputStream ; 38 import java.net.URL ; 39 40 import javax.xml.transform.Source ; 41 import javax.xml.transform.stream.StreamSource ; 42 43 48 public class XMLPerfTest { 49 50 private static final String [] ENGINES = { 51 "jd.xml.xslt.trax.TransformerFactoryImpl", 52 "net.sf.saxon.TransformerFactoryImpl", 53 "org.apache.xalan.processor.TransformerFactoryImpl", }; 54 55 private static final String [] TEMPLATES = { 56 "copy.xsl", 57 "linenumbers.xsl", 58 "profile.xsl", }; 59 60 public static void main(String [] args) throws Exception { 61 System.err.println("Comparing XSLT performance for ASM XSLT"); 62 System.err.println("This may take 20 to 30 minutes\n"); 63 64 File examplesDir = new File (args[0]); 65 if (!examplesDir.isDirectory()) { 66 System.err.println(args[0] + " must be directory"); 67 return; 68 } 69 70 76 for (int i = 0; i < ENGINES.length; i++) { 77 System.err.println(ENGINES[i]); 78 process(null, ENGINES[i]); 79 for (int j = 0; j < TEMPLATES.length; j++) { 80 process(new File (examplesDir, TEMPLATES[j]).getAbsolutePath(), 81 ENGINES[i]); 82 } 83 System.err.println(); 84 } 85 86 } 87 88 private static void process(String name, String engine) throws Exception { 89 System.setProperty("javax.xml.transform.TransformerFactory", engine); 90 processRep(name, Processor.BYTECODE); 91 processRep(name, Processor.MULTI_XML); 92 processRep(name, Processor.SINGLE_XML); 93 } 94 95 117 private static void processRep(String name, int outRep) { 118 long l1 = System.currentTimeMillis(); 119 int n = 0; 120 try { 121 Class c = XMLPerfTest.class; 122 String u = c.getResource("/java/lang/String.class").toString(); 123 final InputStream is = new BufferedInputStream (new URL (u.substring(4, 124 u.indexOf('!'))).openStream()); 125 final OutputStream os = new IgnoringOutputStream(); 126 final StreamSource xslt = name == null 127 ? null 128 : new StreamSource (new FileInputStream (name)); 129 130 Processor p = new DotObserver(Processor.BYTECODE, 131 outRep, 132 is, 133 os, 134 xslt); 135 n = p.process(); 136 137 } catch (Exception ex) { 138 System.err.println(); 139 System.err.println(ex); 141 142 } 143 144 long l2 = System.currentTimeMillis(); 145 146 System.err.println(); 147 System.err.println(" " + outRep + " " + name + " " + (l2 - l1) 148 + "ms " + (1000f * n / (l2 - l1))); 149 150 } 164 165 private static final class DotObserver extends Processor { 166 private int n = 0; 167 168 public DotObserver( 169 int inRepresenation, 170 int outRepresentation, 171 InputStream input, 172 OutputStream output, 173 Source xslt) 174 { 175 super(inRepresenation, outRepresentation, input, output, xslt); 176 } 177 178 public void update(Object arg) { 179 n++; 180 if ((n % 1000) == 0) { 181 System.err.print("" + (n / 1000)); 182 } else if ((n % 100) == 0) { 183 System.err.print("."); 184 } 185 } 186 } 187 188 private static final class IgnoringOutputStream extends OutputStream { 189 190 public final void write(int b) throws IOException { 191 } 192 193 public final void write(byte[] b) throws IOException { 194 } 195 196 public final void write(byte[] b, int off, int len) throws IOException { 197 } 198 } 199 } 200 | Popular Tags |