dd6d96cbb05df24713d439e9e7097e9d6b0b5654.svn-base 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. // $Rev: 130 $
  3. // -----------------------------------------------------------------------------
  4. error_reporting(E_ALL);
  5. include_once('../../simple_html_dom_reader.php');
  6. $filename = '../html/google.htm';
  7. function dump_memory() {
  8. echo 'peak: ' . number_format(memory_get_peak_usage(), 0, '.', ',') . ' bytes, end: ' . number_format(memory_get_usage(), 0, '.', ',') . " bytes<br>";
  9. }
  10. function stat_dom($dom) {
  11. $count_text = 0;
  12. $count_comm = 0;
  13. $count_elem = 0;
  14. $count_tag_end = 0;
  15. foreach($dom->nodes as $n) {
  16. if ($n->nodetype==HDOM_TYPE_TEXT)
  17. ++$count_text;
  18. if ($n->nodetype==HDOM_TYPE_COMMENT)
  19. ++$count_comm;
  20. if ($n->nodetype==HDOM_TYPE_ELEMENT)
  21. ++$count_elem;
  22. if ($n->nodetype==HDOM_TYPE_ENDTAG)
  23. ++$count_tag_end;
  24. }
  25. echo 'Total: '. count($dom->nodes).', Text: '.$count_text.', Commnet: '.$count_comm.', Tag: '.$count_elem.', End Tag: '.$count_tag_end.'<br>';
  26. }
  27. echo 'init ' . number_format(memory_get_usage(), 0, '.', ',') . " bytes";
  28. echo '<br><br>[load file]<br>init memory: '.number_format(memory_get_usage(), 0, '.', ',').'<br>';
  29. echo '------------------------------------------<br>';
  30. flush();
  31. for($i=0; $i<3; ++$i) {
  32. $str = file_get_contents($filename);
  33. unset($str);
  34. dump_memory();
  35. }
  36. echo 'final: '.number_format(memory_get_usage(), 0, '.', ',').'<br>';
  37. flush();
  38. $str = file_get_contents($filename);
  39. echo '<br><br>[multi objects str_get_dom clear memory]<br>init memory: '.number_format(memory_get_usage(), 0, '.', ',').'<br>';
  40. echo '------------------------------------------<br>';
  41. flush();
  42. for($i=0; $i<3; ++$i) {
  43. $dom = str_get_dom($str);
  44. //stat_dom($dom);
  45. $dom->clear();
  46. unset($dom);
  47. dump_memory();
  48. flush();
  49. }
  50. echo 'final: '.number_format(memory_get_usage(), 0, '.', ',').'<br>';
  51. flush();
  52. echo '<br><br>[multi objects file_get_dom clear memory]<br>init memory: '.number_format(memory_get_usage(), 0, '.', ',').'<br>';
  53. echo '------------------------------------------<br>';
  54. flush();
  55. for($i=0; $i<3; ++$i) {
  56. $dom = file_get_dom($filename);
  57. //stat_dom($dom);
  58. $dom->clear();
  59. unset($dom);
  60. dump_memory();
  61. flush();
  62. }
  63. echo 'final: '.number_format(memory_get_usage(), 0, '.', ',').'<br>';
  64. flush();
  65. echo '<br><br>[one object]<br>init memory: '.number_format(memory_get_usage(), 0, '.', ',').'<br>';
  66. echo '------------------------------------------<br>';
  67. flush();
  68. $dom = new simple_html_dom;
  69. for($i=0; $i<3; ++$i) {
  70. $dom->load_file($filename);
  71. $dom->clear();
  72. dump_memory();
  73. }
  74. unset($dom);
  75. echo 'final: '.number_format(memory_get_usage(), 0, '.', ',').'<br>';
  76. flush();
  77. echo '<br><br>[multi objects without clear memory]<br>init memory: '.number_format(memory_get_usage(), 0, '.', ',').'<br>';
  78. echo '------------------------------------------<br>';
  79. flush();
  80. for($i=0; $i<3; ++$i) {
  81. $dom = file_get_dom($filename);
  82. dump_memory();
  83. }
  84. echo 'final: '.number_format(memory_get_usage(), 0, '.', ',').'<br>';
  85. flush();
  86. ?>