1 21 22 package nu.xom.benchmarks; 23 24 import javax.xml.parsers.DocumentBuilder ; 25 import javax.xml.parsers.DocumentBuilderFactory ; 26 27 import org.w3c.dom.DOMImplementation ; 28 29 import nu.xom.Builder; 30 import nu.xom.Document; 31 import nu.xom.Element; 32 import nu.xom.converters.DOMConverter; 33 34 46 class DOMConverterBench { 47 48 private static String elementData = "<zazy>\n" 49 + "<or>476w4l73</or>\n" 50 + "<kfjjiz>6729</kfjjiz>\n" 51 + "<yzsyk>N-Vgj / Yvv Zjysbeu Wwvmk @Yhwc 3=</yzsyk>\n" 52 + "<xibwh>gmaj/zhffyi</xibwh>\n" 53 + "<okq> RUWU: 7124 GR0Z: 20</okq>\n" 54 + "<fmido phpub='3' upfylj='520'>Njm Qmskwo</fmido>\n" 55 + "<fmido phpub='4' upfylj='58312'>Tgnnja Fvwlc</fmido>\n" 56 + "<fmido phpub='4' upfylj='53300'>Iii Pbou Ia Yniugiq</fmido>\n" 57 + "<fmido phpub='5' upfylj='07978'>Vzbpqhud Fm Ptwv</fmido>\n" 58 + "<fmido phpub='6' upfylj='86987'>Fu Ffe Uxvkf</fmido>\n" 59 + "<fmido phpub='6' upfylj='15968'>Kw Biv Bh Ngu Rpaw</fmido>\n" 60 + "<fmido phpub='5' upfylj='94511'>Pnzm Vj Qav Tapnie</fmido>\n" 61 + "<fmido phpub='9' upfylj='90284'>Pawqj Dkqxaslb</fmido>\n" 62 + "<fmido phpub='9' upfylj='44613'>Hsb Aotlml Faa Vpbotugw</fmido>\n" 63 + "<fmido phpub='01' upfylj='369255'>Wvex Wwlrr'o Rnbklfz</fmido>\n" 64 + "<fmido phpub='45' upfylj='787725'>Sdu Edrbo</fmido>\n" 65 + "<fmido phpub='52' upfylj='201908'>Urvr Ot Udbq</fmido>\n" 66 + "<fmido phpub='07' upfylj='025982'>Prgovq Mrm</fmido>\n" 67 + "<fmido phpub='34' upfylj='297465'>Nxr'l Zgoh Zvtl</fmido>\n" 68 + "<fmido phpub='97' upfylj='389353'>Vkcixopj Ccdo</fmido>\n" 69 + "<fmido phpub='51' upfylj='212507'>Dlx'h Rclq Mtxiba Gim</fmido>\n" 70 + "<fmido phpub='36' upfylj='214427'>Bepj Hbrvmgp</fmido>\n" 71 + "<fmido phpub='08' upfylj='523903'>Khxh Anpl</fmido>\n" 72 + "</zazy>\n"; 73 74 75 public static void main(String [] args) throws Exception { 76 77 Runtime r = Runtime.getRuntime(); 78 long memory = r.totalMemory() - r.freeMemory(); 79 80 System.out.println("Initial: " + memory); 81 82 Builder builder = new Builder (); 83 Document dataDoc = builder.build(elementData, "http://www.example.com"); 84 Element root = new Element("root"); 85 Document doc = new Document(root); 86 Element dataElement = dataDoc.getRootElement(); 87 88 89 for (int i = 0; i < 30000; i++) { 90 root.appendChild(dataElement.copy()); 91 } 92 93 System.out.println("Built document: " 94 + (r.totalMemory() - r.freeMemory())/(1024.0*1024) + "MB"); 95 System.gc(); System.gc(); System.gc(); 96 System.out.println("After garbage collection: " 97 + (r.totalMemory() - r.freeMemory())/(1024.0*1024) + "MB"); 98 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 99 factory.setNamespaceAware(true); 100 DocumentBuilder jaxp = factory.newDocumentBuilder(); 101 DOMImplementation impl = jaxp.getDOMImplementation(); 102 103 System.gc(); System.gc(); System.gc(); 104 DOMConverter.convert(doc, impl); 106 DOMConverter.convert(doc, impl); 107 DOMConverter.convert(doc, impl); 108 System.out.println("Warmed up: " 109 + ((r.totalMemory() - r.freeMemory())/(1024.0*1024)) + "MB"); 110 System.gc(); System.gc(); System.gc(); 111 114 long pre = System.currentTimeMillis(); 116 DOMConverter.convert(doc, impl); 117 long post = System.currentTimeMillis(); 118 System.out.println((post - pre)/1000.0 + "s to convert document"); 119 120 } 121 122 } 123 | Popular Tags |