performance.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. require '../lib/SqlFormatter.php';
  3. //this is the default value
  4. //set to '0' to disable caching
  5. //a value between 10 and 20 seems to give the best result
  6. SqlFormatter::$max_cachekey_size = 15;
  7. //the sample query file is filled with install scripts for PrestaShop
  8. //and some sample catalog data from Magento
  9. $contents = file_get_contents('sql.sql');
  10. //queries are separated by 2 new lines
  11. $queries = explode("\n\n",$contents);
  12. //track time and memory usage
  13. $start = microtime(true);
  14. $ustart = memory_get_usage(true);
  15. //track number of queries and size of queries
  16. $num = 0;
  17. $chars = 0;
  18. foreach ($queries as $query) {
  19. //do formatting and highlighting
  20. SqlFormatter::format($query);
  21. $num++;
  22. $chars += strlen($query);
  23. }
  24. $uend = memory_get_usage(true);
  25. $end = microtime(true);
  26. echo "<p>Formatted ".$num." queries using a max_cachekey_size of ".SqlFormatter::$max_cachekey_size."</p>";
  27. echo "<p>Average query length of ".number_format($chars/$num,5)." characters</p>";
  28. echo "<p>Took ".number_format($end-$start,5)." seconds total, ".number_format(($end-$start)/$num,5)." seconds per query, ".number_format(1000*($end-$start)/$chars,5)." seconds per 1000 characters</p>";
  29. echo "<p>Used ".number_format($uend-$ustart)." bytes of memory</p>";
  30. echo "<h3>Cache Stats</h3><pre>".print_r(SqlFormatter::getCacheStats(),true)."</pre>";