/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk

« back to all changes in this revision

Viewing changes to parse/scripts/libxml.ruby

  • Committer: Suren A. Chilingaryan
  • Date: 2009-10-08 03:17:59 UTC
  • Revision ID: csa@dside.dyndns.org-20091008031759-u5ys779huye7feni
LibXML Pull Parser, FAXPP Parser, Mono security benchmark, multiple fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
def siblings(node)
19
19
    res = 0
20
20
 
21
 
    i=0;
22
 
    node.children.each { |cur_node|
23
 
        break if (i+=1)>3
24
 
    }
 
21
#    i=0;
 
22
#    node.children.each { |cur_node|
 
23
#       break if (i+=1)>3
 
24
#    }
 
25
#    cond = if (i>3); 1 else; nil end
25
26
    
26
 
    cond = if (i>3); 1 else; nil end
 
27
    cond = (node.children.length>3)?1:nil;
27
28
        
28
29
    node.children.each { |cur_node|
29
30
        if cur_node.element?
30
31
            if cond
31
 
                res += calc(cur_node)
 
32
#               res += calc(cur_node)
 
33
                val = Float(cur_node.child.content) rescue 0 if (cur_node.child and cur_node.child.text?())
 
34
                if (val)
 
35
                    res += val
 
36
                else
 
37
                    cur_node.each_attr do |attr|
 
38
                        val = Float(attr.child.content) rescue 0
 
39
                        if (val)
 
40
                            res += val
 
41
                            break
 
42
                        end
 
43
                    end
 
44
                end
32
45
            end
33
46
            res += siblings(cur_node)
34
47
        end
35
48
    }
36
 
    
37
49
    return res
38
50
end
39
51
 
44
56
    if (walk)
45
57
#       This is slowest 330 ms
46
58
#       sum = siblings(doc.root)
47
 
        
 
59
 
48
60
        sum = 0
49
61
#       doc.find("//*[(@* or text()) and (count(../child::*)>3)]").each do |node|
50
62
 
 
63
 
 
64
#       nodes = doc.find("//*[(number(@*) or number(text())) and (count(../child::*)>3)]")
 
65
#       nodes.each do |node|
 
66
 
51
67
        doc.find("//*[(number(@*) or number(text())) and (count(../child::*)>3)]").each do |node|
52
68
#           190 ms
53
69
#           sum += calc(node)
67
83
                end
68
84
            end
69
85
        end
 
86
#       nodes = nil
70
87
 
71
88
=begin
72
89
        sum = doc.find("//*[(number(@*) or number(text())) and (count(../child::*)>3)]").map { |node|