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

  1.  
  2. # Run this script w/ 8.6.8 tclsh
  3. #
  4. # Do the same w/ 8.5.19.
  5. #
  6. # My results:
  7. #
  8. # 8.6.8:
  9. #
  10. # Canonical:
  11. # 235248 microseconds per iteration
  12. #
  13. # Tricky (Welch):
  14. # 13551242 microseconds per iteration
  15. #
  16. # 8.5.19:
  17. #
  18. # Canonical:
  19. # 202900 microseconds per iteration
  20. #
  21. # Tricky (Welch):
  22. # 75465 microseconds per iteration
  23.  
  24. package require tdom
  25.  
  26. # Canonical
  27. expat pushparserCanonical \
  28. -elementstartcommand elementstart \
  29. -elementendcommand elementend \
  30. -characterdatacommand cdata
  31.  
  32. proc elementstart {name atts} {
  33. global expatstr
  34.  
  35. append expatstr $name
  36. foreach {attname attvalue} $atts {
  37. append expatstr $attname $attvalue
  38. }
  39. }
  40.  
  41. proc elementend {name} {
  42. global expatstr
  43.  
  44. append expatstr /$name
  45. }
  46.  
  47. proc cdata {cdata} {
  48. global expatstr
  49.  
  50. append expatstr $cdata
  51. }
  52.  
  53. # Tricky (Welch).
  54. expat pushparserTricky \
  55. -elementstartcommand elementstart \
  56. -elementendcommand elementend \
  57. -characterdatacommand cdata
  58.  
  59. # We need some larger XML file
  60. #
  61. # Lemme create that for you, just for convenience. Any larger input by
  62. # your own should do it also.
  63. set xml "<doc>"
  64. lappend xml [string repeat "<some><child>data</child></some>" 20000]
  65. lappend xml "</doc>"
  66.  
  67. puts "Canonical:"
  68. puts [time {pushparserCanonical parse $xml}]
  69. puts ""
  70. puts "Tricky (Welch):"
  71. puts [time {pushparserTricky parse $xml}]
  72.  
  73.