php - Is array_key() the fastest solution for this? -
i'm writing application research deals big arrays , lots of iterations on values. reducing calculation time, i'm implementing several improvements in codes. right now, after several improvements, calculation time still bit high. array_key()
function 1 consumes almost half of calculation time. there better substitute that?
i'm creating example simple version (without iteration loops) of need improve:
$bigarray=array_fill(0,1000000,0); for($i=0;$i<10;$i++){ $rnd=mt_rand(0,1000000); $bigarray[$rnd]=1; } $start=microtime(true); $list=array_keys($bigarray,1); $end=microtime(true); echo $end-$start;
the outcome 0.021490097045898
seconds. know faster way this? small improvement helpful since kind of calculation go hundreds of thousands of rounds , time reaches 30 seconds , half of array_key()
function described above.
btw, i'm running script on dual core (intel) e8500 @3.16ghz,3.17ghz 8gb ram, os windows 7 64-bit (just in case).
thanks in advance.
credit goes @wikken comments:
if it's 1's , 0's, array_filter() performs twice fast array_keys() here.
it helpful , performs job fast. reduced time %20 in case. wikken!
Comments
Post a Comment