File: pushpull.bench

package info (click to toggle)
tdom 0.9.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,260 kB
  • sloc: ansic: 56,762; xml: 20,797; tcl: 3,618; sh: 658; makefile: 83; cpp: 30
file content (115 lines) | stat: -rw-r--r-- 2,701 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- tcl -*-
#
# This file contains a number of benchmarks for push (expat) and pull
# (tdom::pullparser) parser.
#
# (c) 2018 Rolf Ade <rolf@pointsman.de>
#


# ### ### ### ######### ######### ######### ###########################
## Setting up the environment ...

package require tdom 

# ### ### ### ######### ######### ######### ###########################
## Benchmarks.


proc loopPullE {} {
    while {[set state [pullparser next]] ne "END_DOCUMENT"} {
        switch $state {
            "START_TAG" {
                append pullstr [pullparser tag]
                foreach {attname attvalue} [pullparser attributes] {
                    append pullstr $attname $attvalue
                }
            }
            "TEXT" {
                append pullstr [pullparser text]
            }
            "END_TAG" {
                append pullstr /[pullparser tag]
            }
        }
    }
    return $pullstr
}

expat pushparserCanonical \
    -elementstartcommand elementstart \
    -elementendcommand elementend \
    -characterdatacommand cdata


proc elementstart {name atts} {
    global expatstr

    append expatstr $name
    foreach {attname attvalue} $atts {
        append expatstr $attname $attvalue
    }
}

proc elementend {name} {
    global expatstr

    append expatstr /$name
}

proc cdata {cdata} {
    global expatstr

    append expatstr $cdata
}

expat pushparserTricky \
    -elementstartcommand elementstart \
    -elementendcommand elementend \
    -characterdatacommand cdata


proc dopull {} {
    while {[set state [pullparser next]] ne "END_DOCUMENT"} {
        switch $state {
            "START_TAG" {
                append pullstr [pullparser tag]
                foreach {attname attvalue} [pullparser attributes] {
                    append pullstr $attname $attvalue
                }
            }
            "TEXT" {
                append pullstr [pullparser text]
            }
            "END_TAG" {
                append pullstr /[pullparser tag]
            }
        }
    }
    return $pullstr
}
bench -desc "push/canonical mondial-europe.xml" -iters 5 -body {
    set expatstr ""
    pushparserCanonical parsefile ../tests/data/mondial-europe.xml
    pushparserCanonical reset
} -post {
    pushparserCanonical free
}

bench -desc "push/tricky mondial-europe.xml" -iters 5 -body {
    set expatstr ""
    pushparserTricky parsefile ../tests/data/mondial-europe.xml
    pushparserTricky reset
} -post {
    pushparserTricky free
}

tdom::pullparser pullparser

bench -desc "pull mondial-europe.xml" -iters 5 -body {
    pullparser inputfile ../tests/data/mondial-europe.xml
    dopull
    pullparser reset
} -post {
    pullparser delete
}