Posted to tcl by de at Wed Feb 28 13:58:12 GMT 2018view raw

  1.  
  2. # Run this script w/ 8.6.8 tclsh
  3. #
  4. # Do the same w/ 8.5.19.
  5.  
  6. package require tdom
  7.  
  8. # Canonical
  9. expat pushparserCanonical \
  10. -elementstartcommand elementstart
  11.  
  12. proc elementstart {name atts} {
  13. global str
  14.  
  15. append str $name
  16. }
  17.  
  18. puts [tcl::unsupported::disassemble proc elementstart]
  19.  
  20. # Tricky (Welch).
  21. expat pushparserTricky \
  22. -elementstartcommand elementstart
  23.  
  24. # We need some larger XML file
  25. #
  26. # Lemme create that for you, just for convenience. Any larger input by
  27. # your own should do it also.
  28. set xml "<doc>"
  29. lappend xml [string repeat "<some><child>data</child></some>" 20000]
  30. lappend xml "</doc>"
  31.  
  32. puts "Canonical:"
  33. puts [time {pushparserCanonical parse $xml}]
  34. puts ""
  35. puts "Tricky (Welch):"
  36. puts [time {pushparserTricky parse $xml}]
  37.  
  38.  
  39.  
  40. With tcl 8.5:
  41. ByteCode 0x0x94d0f0, refCt 1, epoch 3, interp 0x0x878c80 (epoch 3)
  42. Source "\n global str\n \n append str $name\n"
  43. Cmds 2, src 42, inst 27, litObjs 3, aux 0, stkDepth 2, code/src 0.00
  44. Proc 0x0x923ac0, refCt 1, args 2, compiled locals 3
  45. slot 0, scalar, arg, "name"
  46. slot 1, scalar, arg, "atts"
  47. slot 2, scalar, "str"
  48. Commands 2:
  49. 1: pc 0-12, src 5-14 2: pc 13-25, src 25-40
  50. Command 1: "global str"
  51. (0) push1 0 # "::"
  52. (2) push1 1 # "str"
  53. (4) nsupvar %v2 # var "str"
  54. (9) pop
  55. (10) push1 2 # ""
  56. (12) pop
  57. Command 2: "append str $name"
  58. (13) startCommand +13 1 # next cmd at pc 26
  59. (22) loadScalar1 %v0 # var "name"
  60. (24) appendScalar1 %v2 # var "str"
  61. (26) done
  62.  
  63. Canonical:
  64. 93046 microseconds per iteration
  65.  
  66. Tricky (Welch):
  67. 33559 microseconds per iteration
  68.  
  69.  
  70. With 8.6:
  71.  
  72. ByteCode 0x0xdc4d00, refCt 1, epoch 17, interp 0x0xc2ad10 (epoch 17)
  73. Source "\n global str\n \n append str $na..."
  74. File "/home/rolf/hack/tdom-pull/unix/pg3.tcl" Line 12
  75. Cmds 2, src 42, inst 27, litObjs 3, aux 0, stkDepth 2, code/src 0.00
  76. Proc 0x0xd017d0, refCt 1, args 2, compiled locals 3
  77. slot 0, scalar, arg, "name"
  78. slot 1, scalar, arg, "atts"
  79. slot 2, scalar, "str"
  80. Commands 2:
  81. 1: pc 0-12, src 5-14 2: pc 13-25, src 25-40
  82. Command 1: "global str..."
  83. (0) push1 0 # "::"
  84. (2) push1 1 # "str"
  85. (4) nsupvar %v2 # var "str"
  86. (9) pop
  87. (10) nop
  88. (11) nop
  89. (12) nop
  90. Command 2: "append str $name..."
  91. (13) startCommand +13 1 # next cmd at pc 26, 1 cmds start here
  92. (22) loadScalar1 %v0 # var "name"
  93. (24) appendScalar1 %v2 # var "str"
  94. (26) done
  95.  
  96. Canonical:
  97. 101761 microseconds per iteration
  98.  
  99. Tricky (Welch):
  100. 3030611 microseconds per iteration
  101.  
  102.  
  103.  
  104.