Created
December 19, 2012 15:59
-
-
Save xintron/4337783 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$data = array(); | |
$time = array(); | |
for ($i = 97; $i < 173; $i++) | |
$data[chr($i)] = $i; | |
$s = microtime(true); | |
for ($i = 0; $i < 1000000; $i++) { | |
isset($data['g']); | |
} | |
$time['isset'] = microtime(true)-$s; | |
printf("isset time:\t\t\t%f\n", $time['isset']); | |
$s = microtime(true); | |
for ($i = 0; $i < 1000000; $i++) { | |
array_key_exists('g', $data); | |
} | |
$time['array_key_exists'] = microtime(true)-$s; | |
printf("array_key_exists time:\t\t%f\n", $time['array_key_exists']); | |
if ($time['isset'] < $time['array_key_exists']) | |
printf("isset is faster by:\t\t %.2f%%", (($time['array_key_exists']-$time['isset'])*100/$time['isset'])); | |
else | |
printf("array_key_exists is faster by:\t %.2f%%", (($time['isset']-$time['array_key_exists'])*100/$time['array_key_exists'])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment