I have found that array_key_exists
is over 1000x slower than isset
at check if a key is set in an array reference. Does anyone that has an understa
Not array_key_exists, but the removal of the reference (= NULL) causes this. I commented it out from your script and this is the result:
array_key_exists( $my_array ) 0.0059430599212646
isset( $my_array ) 0.0027170181274414
array_key_exists( $my_array_ref ) 0.0038740634918213
isset( $my_array_ref ) 0.0025200843811035
Only removed the unsetting from the array_key_exists( $my_array_ref )
part, this is the modified part for reference:
$my_array = array();
$my_array_ref = &$my_array;
$start = microtime( TRUE );
for( $i = 1; $i < 10000; $i++ ) {
array_key_exists( $i, $my_array_ref );
// $my_array_ref[$i] = NULL;
}
$stop = microtime( TRUE );
print "array_key_exists( \$my_array_ref ) ".($stop-$start).PHP_EOL;
unset( $my_array, $my_array_ref, $start, $stop, $i );