Posted to tcl by de at Wed Feb 28 13:58:12 GMT 2018view raw
- # Run this script w/ 8.6.8 tclsh
- #
- # Do the same w/ 8.5.19.
- package require tdom
- # Canonical
- expat pushparserCanonical \
- -elementstartcommand elementstart
- proc elementstart {name atts} {
- global str
- append str $name
- }
- puts [tcl::unsupported::disassemble proc elementstart]
- # Tricky (Welch).
- expat pushparserTricky \
- -elementstartcommand elementstart
- # 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}]
- With tcl 8.5:
- ByteCode 0x0x94d0f0, refCt 1, epoch 3, interp 0x0x878c80 (epoch 3)
- Source "\n global str\n \n append str $name\n"
- Cmds 2, src 42, inst 27, litObjs 3, aux 0, stkDepth 2, code/src 0.00
- Proc 0x0x923ac0, refCt 1, args 2, compiled locals 3
- slot 0, scalar, arg, "name"
- slot 1, scalar, arg, "atts"
- slot 2, scalar, "str"
- Commands 2:
- 1: pc 0-12, src 5-14 2: pc 13-25, src 25-40
- Command 1: "global str"
- (0) push1 0 # "::"
- (2) push1 1 # "str"
- (4) nsupvar %v2 # var "str"
- (9) pop
- (10) push1 2 # ""
- (12) pop
- Command 2: "append str $name"
- (13) startCommand +13 1 # next cmd at pc 26
- (22) loadScalar1 %v0 # var "name"
- (24) appendScalar1 %v2 # var "str"
- (26) done
- Canonical:
- 93046 microseconds per iteration
- Tricky (Welch):
- 33559 microseconds per iteration
- With 8.6:
- ByteCode 0x0xdc4d00, refCt 1, epoch 17, interp 0x0xc2ad10 (epoch 17)
- Source "\n global str\n \n append str $na..."
- File "/home/rolf/hack/tdom-pull/unix/pg3.tcl" Line 12
- Cmds 2, src 42, inst 27, litObjs 3, aux 0, stkDepth 2, code/src 0.00
- Proc 0x0xd017d0, refCt 1, args 2, compiled locals 3
- slot 0, scalar, arg, "name"
- slot 1, scalar, arg, "atts"
- slot 2, scalar, "str"
- Commands 2:
- 1: pc 0-12, src 5-14 2: pc 13-25, src 25-40
- Command 1: "global str..."
- (0) push1 0 # "::"
- (2) push1 1 # "str"
- (4) nsupvar %v2 # var "str"
- (9) pop
- (10) nop
- (11) nop
- (12) nop
- Command 2: "append str $name..."
- (13) startCommand +13 1 # next cmd at pc 26, 1 cmds start here
- (22) loadScalar1 %v0 # var "name"
- (24) appendScalar1 %v2 # var "str"
- (26) done
- Canonical:
- 101761 microseconds per iteration
- Tricky (Welch):
- 3030611 microseconds per iteration