run.php 740 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. require __DIR__ . '/../../vendor/autoload.php';
  3. $iterations = isset($argv[1]) ? $argv[1] : 100;
  4. $html5 = new Masterminds\HTML5();
  5. $content = file_get_contents(__DIR__ . '/example.html');
  6. $dom = $html5->loadHTML($content);
  7. $samples = array();
  8. for ($i = 0; $i < $iterations; ++$i) {
  9. $t = microtime(true);
  10. $dom = $html5->loadHTML($content);
  11. $samples[] = microtime(true) - $t;
  12. }
  13. $time = array_sum($samples) / count($samples);
  14. echo 'Loading: ' . ($time * 1000) . "\n";
  15. $samples = array();
  16. for ($i = 0; $i < $iterations; ++$i) {
  17. $t = microtime(true);
  18. $html5->saveHTML($dom);
  19. $samples[] = microtime(true) - $t;
  20. }
  21. $time = array_sum($samples) / count($samples);
  22. echo 'Writing: ' . ($time * 1000) . "\n";
  23. exit(0);