Posted to tcl by de at Thu Jan 21 14:00:43 GMT 2021view raw

  1. #load ./libtdom0.9.3.so
  2. package require tdom 0.9.3
  3.  
  4. set nrNoise 10
  5. set noiseElement "elementNoise"
  6. set nrMeat 40
  7. set meatPrefix "element"
  8. set size 1000000
  9.  
  10. proc generateInput {nrNoise noiseElement nrMeat meatPrefix size} {
  11. set xml "<doc>"
  12. set names [list]
  13. for {set i 0} {$i < $nrMeat} {incr i} {
  14. lappend names $meatPrefix$i
  15. }
  16. while {[string length $xml] < $size} {
  17. for {set i 0} {$i < $nrMeat} {incr i} {
  18. append xml [string repeat "<$noiseElement/>" $nrNoise]
  19. append xml "<$meatPrefix$i/>\n"
  20. }
  21. }
  22. append xml "</doc>"
  23. return [list $xml $names]
  24. }
  25.  
  26. proc testnames {xml names} {
  27. tdom::pullparser pp
  28. pp input $xml
  29. set result [list]
  30. pp next
  31. puts "-names [time {
  32. while {[pp state] ne "END_DOCUMENT"} {
  33. lappend result [pp tag]
  34. pp find-element -names $names
  35. }
  36. }]"
  37. pp delete
  38. }
  39.  
  40. proc testnameshashed {xml names} {
  41. tdom::pullparser pp
  42. pp input $xml
  43. set result [list]
  44. pp next
  45. puts "-names hashed [time {
  46. while {[pp state] ne "END_DOCUMENT"} {
  47. lappend result [pp tag]
  48. pp find-element -names $names -hash
  49. }
  50. }]"
  51. pp delete
  52. }
  53.  
  54. proc testnameshashednext {xml names} {
  55. tdom::pullparser pp
  56. pp input $xml
  57. set result [list]
  58. pp next
  59. puts "-next [time {
  60. pp find-element -names $names
  61. while {[pp state] ne "END_DOCUMENT"} {
  62. lappend result [pp tag]
  63. pp find-element -next
  64. }
  65. }]"
  66. pp delete
  67. }
  68.  
  69. foreach {nrNoise noiseElement nrMeat meatPrefix size} {
  70. 10 "elementNoise" 40 "element" 1000000
  71. 5 "elementNoise" 5 "element" 1000000
  72. 5 "elementNoise" 5 "e" 1000000
  73. 2 "elementNoise" 5 "element" 1000000
  74. 2 "elementNoise" 100 "element" 1000000
  75. 20 "elementNoise" 100 "element" 1000000
  76. 20 "earlydistinct" 100 "element" 1000000
  77. 100 "elementNoise" 20 "element" 1000000
  78. } {
  79. puts "$nrNoise $noiseElement $nrMeat $meatPrefix $size"
  80. lassign [generateInput $nrNoise $noiseElement $nrMeat $meatPrefix $size] xml names
  81. testnames $xml $names
  82. testnameshashed $xml $names
  83. testnameshashednext $xml $names
  84. puts ""
  85. }
  86.  
  87.