5
5
import javax.xml.parsers.DocumentBuilder;
7
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;
9
13
public class intel_dom2 extends bench {
11
DocumentBuilder parser;
12
DocumentBuilderFactory factory;
14
public void InitXML() {
15
DocumentBuilder parser;
16
DocumentBuilderFactory factory;
18
double walker_process_node(Node cur_node) {
22
child = cur_node.getFirstChild();
23
if ((child!=null)&&(child.getNodeType() == Node.TEXT_NODE)) {
25
res = Float.parseFloat(child.getNodeValue());
26
if (res!=0) return res;
27
} catch(Exception e) {
31
NamedNodeMap attrMap = cur_node.getAttributes();
32
int length = attrMap.getLength();
34
for (int i = 0; i < length; i++) {
36
res = Float.parseFloat(attrMap.item(i).getNodeValue());
37
if (res!=0) return res;
38
} catch (Exception e) {
46
double walker(Node node) {
51
for (cur_node = node; cur_node!=null; cur_node = cur_node.getNextSibling()) {
52
if((cur_node.getNodeType() == Node.ELEMENT_NODE)&&(++i>3)) break;
57
for (cur_node = node; cur_node!=null; cur_node = cur_node.getNextSibling()) {
58
if (cur_node.getNodeType() == Node.ELEMENT_NODE) {
60
res += walker_process_node(cur_node);
62
res+=walker(cur_node.getFirstChild());
69
public void InitXML() {
15
70
factory = DocumentBuilderFactory.newInstance();
16
71
factory.setNamespaceAware(true);
17
72
factory.setValidating(false);
19
if (System.getenv("memory_bench")!=null) {
74
// if (System.getenv("memory_bench")!=null) {
75
if (System.getenv("allow_deferring")!=null) {
20
76
factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", true);
22
78
factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
81
if (System.getenv("walk_tree")!=null) {
24
86
} catch (Throwable err) {
25
87
// ignoring missing option
31
93
catch (Throwable err) {
32
94
err.printStackTrace ();
36
public void ParseXML(FileInputStream is, int iters, int iter) {
98
public void ParseXML(FileInputStream is, int iters, int iter) {
38
100
Document doc = parser.parse(is);
102
double res = walker(doc.getFirstChild());
103
// System.out.println("Sum: " + res);
40
106
catch (Exception e)
42
108
System.out.println(e.toString());
46
static public void main(String argv[]) throws IOException {
112
static public void main(String argv[]) throws IOException {
47
113
bench mybench = new intel_dom2();
48
114
mybench.Bench(argv);