1 21 22 package nu.xom.benchmarks; 23 24 import java.io.IOException ; 25 import java.text.DecimalFormat ; 26 27 import nu.xom.Builder; 28 import nu.xom.Document; 29 import nu.xom.Element; 30 import nu.xom.ParsingException; 31 32 42 class BigText { 43 44 static Document makeFullUnicode() { 45 46 Element root = new Element("root"); 47 Document doc = new Document(root); 48 49 StringBuffer sb = new StringBuffer (65536); 50 for (int i = 0x20; i <= 0xD7FF; i++) { 51 sb.append((char) i); 52 } 53 54 56 for (int i = 0xE000; i <= 0xFFFD; i++) { 57 sb.append((char) i); 58 } 59 60 System.gc(); 61 62 for (int i = 0; i < 256; i++) { 67 int u = 0x1D100 + i; 69 int uprime = u - 0x10000; 70 int W1 = 0xD800; 71 int W2 = 0xDC00; 72 W2 = W2 | (uprime & 0x7FF ); 73 W1 = W1 | (uprime & 0xFF800); 74 sb.append( ((char) W1) + "" + ((char) W2) ); 75 } 76 77 root.appendChild(sb.toString()); 78 79 return doc; 80 81 } 82 83 public static void main(String [] args) 84 throws IOException , ParsingException { 85 86 DecimalFormat format = new DecimalFormat (); 87 format.setMaximumFractionDigits(2); 88 Runtime r = Runtime.getRuntime(); 89 System.gc(); System.gc(); System.gc(); 90 long before = r.totalMemory() - r.freeMemory(); 91 Document doc; 92 if (args.length > 0) { 93 Builder builder = new Builder(); 94 doc = builder.build(args[0]); 95 builder = null; 96 } 97 else { 98 doc = makeFullUnicode(); 99 } 100 long after = r.totalMemory() - r.freeMemory(); 101 double usage = (after - before)/(1024.0*1024.0); 102 System.out.println("Memory used: " 103 + format.format(usage) + "M"); 104 System.gc(); System.gc(); System.gc(); 105 long postGC = r.totalMemory() - r.freeMemory(); 106 usage = (postGC - before)/(1024.0*1024.0); 107 System.out.println("Memory used after garbage collection: " 108 + format.format(usage) + "M"); 109 110 System.out.println("Meaningless number: " 112 + doc.toXML().length()); 113 } 114 115 } 116 | Popular Tags |