1 5 package com.hp.hpl.jena.rdf.arp.test; 6 7 import org.xml.sax.*; 8 import org.xml.sax.ContentHandler ; 9 10 import org.apache.xerces.parsers.*; 11 import java.net.*; 12 13 23 public class XMLMemTest implements ContentHandler { 24 static private class DeliberateEnd extends RuntimeException { 25 26 } 27 final private int limit; 28 private int seen = 0; 29 private int chksum = 0; 30 Locator locator; 31 private XMLMemTest(int cnt) { 32 limit = cnt; 33 } 34 40 41 public static void main(String [] args) { 42 XMLMemTest test = 43 new XMLMemTest(args.length > 1 ? Integer.parseInt(args[1]) : -1); 44 SAXParser sax = new SAXParser(); 45 sax.setContentHandler(test); 46 Runtime runtime = Runtime.getRuntime(); 47 runtime.gc(); 48 runtime.gc(); 49 long startMem = runtime.totalMemory() - runtime.freeMemory(); 50 try { 51 for (int i=args.length > 2 ? Integer.parseInt(args[2]) : 1;i>0;i--){ 52 URL url = new URL(args[0]); 53 54 InputSource inputS = new InputSource(url.openStream()); 55 inputS.setSystemId(args[0]); 56 sax.parse(inputS); 57 } 58 } catch (DeliberateEnd e) { 59 60 } catch (Exception e) { 61 e.printStackTrace(); 62 } 63 runtime.gc(); 64 runtime.gc(); 65 long endMem = runtime.totalMemory() - runtime.freeMemory(); 66 System.err.println("Start: "+startMem); 67 System.err.println("End: "+endMem); 68 System.err.println("Used: "+(endMem-startMem)); 69 System.err.println("Count: "+test.seen); 70 System.err.println("Hash: "+test.chksum); 71 } 72 73 78 79 public void setDocumentLocator(Locator locator) { 80 this.locator = locator; 81 82 } 83 84 89 public void startDocument() throws SAXException { 90 } 91 92 97 public void endDocument() throws SAXException { 98 } 99 100 106 public void startPrefixMapping(String prefix, String uri) 107 throws SAXException { 108 } 109 110 115 public void endPrefixMapping(String prefix) throws SAXException { 116 } 117 123 129 public void startElement( 130 String namespaceURI, 131 String localName, 132 String qName, 133 Attributes atts) 134 throws SAXException { 135 if (++seen == limit) 136 throw new DeliberateEnd(); 137 locator.getLineNumber(); 138 locator.getColumnNumber(); 139 152 } 153 154 160 public void endElement(String namespaceURI, String localName, String qName) 161 throws SAXException { 162 } 163 164 169 public void characters(char[] ch, int start, int length) 170 throws SAXException { 171 } 172 173 178 public void ignorableWhitespace(char[] ch, int start, int length) 179 throws SAXException { 180 } 181 182 188 public void processingInstruction(String target, String data) 189 throws SAXException { 190 } 191 192 197 public void skippedEntity(String name) throws SAXException { 198 } 199 } 200 201 | Popular Tags |