Posted to tcl by de at Tue Feb 27 23:47:24 GMT 2018view pretty

# Run this script w/ 8.6.8 tclsh 
#
# Do the same w/ 8.5.19.
#
# My results:
#
# 8.6.8:
#
# Canonical:
# 235248 microseconds per iteration
#
# Tricky (Welch):
# 13551242 microseconds per iteration
#
# 8.5.19:
# 
# Canonical:
# 202900 microseconds per iteration
#
# Tricky (Welch):
# 75465 microseconds per iteration

package require tdom

# Canonical
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
}

# Tricky (Welch).
expat pushparserTricky \
    -elementstartcommand elementstart \
    -elementendcommand elementend \
    -characterdatacommand cdata

# We need some larger XML file
#
# Lemme create that for you, just for convenience. Any larger input by
# your own should do it also.
set xml "<doc>"
lappend xml [string repeat "<some><child>data</child></some>" 20000]
lappend xml "</doc>"

puts "Canonical:"
puts [time {pushparserCanonical parse $xml}]
puts ""
puts "Tricky (Welch):"
puts [time {pushparserTricky parse $xml}]