Advertisement
Crack

phpMyAdmin: array search speed comparison

Jun 7th, 2011
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. <?php
  2. define('PHPMYADMIN', true);
  3. require 'libraries/string.lib.php';
  4. require 'libraries/sqlparser.data.php';
  5.  
  6.  
  7. $iterations = 100000;
  8. $word = 'WRITE';
  9.  
  10. $array_flipped = array_flip($PMA_SQPdata_forbidden_word);
  11. $count = count($PMA_SQPdata_forbidden_word);
  12.  
  13. $t0 = microtime(true);
  14. for ($i = 0; $i < $iterations; $i++) {
  15.     PMA_STR_binarySearchInArr($word, $PMA_SQPdata_forbidden_word, $count);
  16. }
  17.  
  18. $t1 = microtime(true);
  19. for ($i = 0; $i < $iterations; $i++) {
  20.     array_search($word, $PMA_SQPdata_forbidden_word);
  21. }
  22.  
  23. $t2 = microtime(true);
  24. for ($i = 0; $i < $iterations; $i++) {
  25.     isset($array_flipped[$word]);
  26. }
  27.  
  28. $t3 = microtime(true);
  29. for ($i = 0; $i < $iterations; $i++) {
  30.     array_key_exists($word, $array_flipped);
  31. }
  32.  
  33. $t4 = microtime(true);
  34. for ($i = 0; $i < $iterations; $i++);
  35. $t5 = microtime(true);
  36. $loop_overhead = $t5 - $t4;
  37. ?>
  38. <pre style="white-space:pre-wrap;">
  39. Binary search:    <?php echo round($t1-$t0-$loop_overhead, 4) . "\n"; ?>
  40. array_search:     <?php echo round($t2-$t1-$loop_overhead, 4) . "\n"; ?>
  41. isset:            <?php echo round($t3-$t2-$loop_overhead, 4) . "\n"; ?>
  42. array_key_exists: <?php echo round($t4-$t3-$loop_overhead, 4) . "\n"; ?>
  43. </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement