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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -