Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('PHPMYADMIN', true);
- require 'libraries/string.lib.php';
- require 'libraries/sqlparser.data.php';
- $iterations = 100000;
- $word = 'WRITE';
- $array_flipped = array_flip($PMA_SQPdata_forbidden_word);
- $count = count($PMA_SQPdata_forbidden_word);
- $t0 = microtime(true);
- for ($i = 0; $i < $iterations; $i++) {
- PMA_STR_binarySearchInArr($word, $PMA_SQPdata_forbidden_word, $count);
- }
- $t1 = microtime(true);
- for ($i = 0; $i < $iterations; $i++) {
- array_search($word, $PMA_SQPdata_forbidden_word);
- }
- $t2 = microtime(true);
- for ($i = 0; $i < $iterations; $i++) {
- isset($array_flipped[$word]);
- }
- $t3 = microtime(true);
- for ($i = 0; $i < $iterations; $i++) {
- array_key_exists($word, $array_flipped);
- }
- $t4 = microtime(true);
- for ($i = 0; $i < $iterations; $i++);
- $t5 = microtime(true);
- $loop_overhead = $t5 - $t4;
- ?>
- <pre style="white-space:pre-wrap;">
- Binary search: <?php echo round($t1-$t0-$loop_overhead, 4) . "\n"; ?>
- array_search: <?php echo round($t2-$t1-$loop_overhead, 4) . "\n"; ?>
- isset: <?php echo round($t3-$t2-$loop_overhead, 4) . "\n"; ?>
- array_key_exists: <?php echo round($t4-$t3-$loop_overhead, 4) . "\n"; ?>
- </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement