bzr branch
http://darksoft.org/webbzr/xmlbench/trunk
1
by Suren A. Chilingaryan
Initial import |
1 |
import java.io.*; |
2 |
import java.util.*; |
|
3 |
import java.text.*; |
|
4 |
import javax.xml.parsers.DocumentBuilderFactory; |
|
5 |
import javax.xml.parsers.DocumentBuilder; |
|
6 |
||
10
by Suren A. Chilingaryan
DOM Walking for deferred mode parsers |
7 |
import org.w3c.dom.Document; |
8 |
import org.w3c.dom.NamedNodeMap; |
|
9 |
import org.w3c.dom.Node; |
|
10 |
import org.w3c.dom.Text; |
|
11 |
import java.lang.Float; |
|
12 |
||
1
by Suren A. Chilingaryan
Initial import |
13 |
public class sun_dom2 extends bench { |
10
by Suren A. Chilingaryan
DOM Walking for deferred mode parsers |
14 |
int walk_mode; |
15 |
DocumentBuilder parser; |
|
16 |
DocumentBuilderFactory factory; |
|
17 |
||
18 |
double walker_process_node(Node cur_node) { |
|
19 |
double res; |
|
20 |
Node child; |
|
21 |
||
22 |
child = cur_node.getFirstChild(); |
|
23 |
if ((child!=null)&&(child.getNodeType() == Node.TEXT_NODE)) { |
|
24 |
try { |
|
25 |
res = Float.parseFloat(child.getNodeValue()); |
|
26 |
if (res!=0) return res; |
|
27 |
} catch(Exception e) { |
|
28 |
}
|
|
29 |
}
|
|
30 |
||
31 |
NamedNodeMap attrMap = cur_node.getAttributes(); |
|
32 |
int length = attrMap.getLength(); |
|
33 |
||
34 |
for (int i = 0; i < length; i++) { |
|
35 |
try { |
|
36 |
res = Float.parseFloat(attrMap.item(i).getNodeValue()); |
|
37 |
if (res!=0) return res; |
|
38 |
} catch (Exception e) { |
|
39 |
}
|
|
40 |
}
|
|
41 |
||
42 |
return 0; |
|
43 |
}
|
|
44 |
||
45 |
||
46 |
double walker(Node node) { |
|
47 |
int i = 0; |
|
48 |
double res = 0; |
|
49 |
Node cur_node; |
|
50 |
||
51 |
for (cur_node = node; cur_node!=null; cur_node = cur_node.getNextSibling()) { |
|
52 |
if((cur_node.getNodeType() == Node.ELEMENT_NODE)&&(++i>3)) break; |
|
53 |
}
|
|
54 |
||
55 |
if (i<=3) i = 0; |
|
56 |
||
57 |
for (cur_node = node; cur_node!=null; cur_node = cur_node.getNextSibling()) { |
|
58 |
if (cur_node.getNodeType() == Node.ELEMENT_NODE) { |
|
59 |
if (i>0) { |
|
60 |
res += walker_process_node(cur_node); |
|
61 |
}
|
|
62 |
res+=walker(cur_node.getFirstChild()); |
|
63 |
}
|
|
64 |
}
|
|
65 |
return res; |
|
66 |
}
|
|
67 |
||
68 |
public void InitXML() { |
|
1
by Suren A. Chilingaryan
Initial import |
69 |
factory = DocumentBuilderFactory.newInstance(); |
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
70 |
factory.setNamespaceAware(true); |
71 |
factory.setValidating(false); |
|
72 |
||
73 |
try { |
|
74 |
if (System.getenv("allow_deferring")!=null) { |
|
75 |
factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", true); |
|
76 |
} else { |
|
77 |
factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false); |
|
78 |
}
|
|
10
by Suren A. Chilingaryan
DOM Walking for deferred mode parsers |
79 |
|
80 |
if (System.getenv("walk_tree")!=null) { |
|
81 |
walk_mode = 1; |
|
82 |
} else { |
|
83 |
walk_mode = 0; |
|
84 |
}
|
|
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
85 |
} catch (Throwable err) { |
86 |
// ignoring missing option
|
|
87 |
}
|
|
88 |
||
1
by Suren A. Chilingaryan
Initial import |
89 |
try { |
90 |
parser = factory.newDocumentBuilder(); |
|
91 |
}
|
|
92 |
catch (Throwable err) { |
|
93 |
err.printStackTrace (); |
|
94 |
}
|
|
10
by Suren A. Chilingaryan
DOM Walking for deferred mode parsers |
95 |
}
|
1
by Suren A. Chilingaryan
Initial import |
96 |
|
10
by Suren A. Chilingaryan
DOM Walking for deferred mode parsers |
97 |
public void ParseXML(FileInputStream is, int iters, int iter) { |
1
by Suren A. Chilingaryan
Initial import |
98 |
try { |
10
by Suren A. Chilingaryan
DOM Walking for deferred mode parsers |
99 |
Document doc = parser.parse(is); |
100 |
if (walk_mode!=0) { |
|
101 |
double res = walker(doc.getFirstChild()); |
|
102 |
// System.out.println("Sum: " + res);
|
|
103 |
}
|
|
1
by Suren A. Chilingaryan
Initial import |
104 |
}
|
105 |
catch (Exception e) |
|
106 |
{
|
|
107 |
System.out.println(e.toString()); |
|
108 |
}
|
|
10
by Suren A. Chilingaryan
DOM Walking for deferred mode parsers |
109 |
}
|
1
by Suren A. Chilingaryan
Initial import |
110 |
|
10
by Suren A. Chilingaryan
DOM Walking for deferred mode parsers |
111 |
static public void main(String argv[]) throws IOException { |
1
by Suren A. Chilingaryan
Initial import |
112 |
bench mybench = new sun_dom2(); |
113 |
mybench.Bench(argv); |
|
10
by Suren A. Chilingaryan
DOM Walking for deferred mode parsers |
114 |
}
|
1
by Suren A. Chilingaryan
Initial import |
115 |
}
|