Thanks for the sample program, why didn't I think of that myself :)
Marcus Agehall (Roxen IS) @ Pike (-) developers forum wrote:
I think they are pretty much the same, but for clarity I usually use the has_index() function instead.
I made a small testprogram for you, so that you can benchmark it youself:
int main(int argc, array(string) argv) { int len = (int)argv[1];
array x = allocate(len, random); int rpt = (int)argv[2];
int elem = -1;
werror("Running %d iterations on array of size %d\n", rpt, len);
float t = gauge { for(int i=0; i < rpt; i++) { if (search(x, elem) == -1) { ; }; } };
werror("==-1 took %fs\n", t);
t = gauge { for(int i=0; i < rpt; i++) { if (search(x, elem) < 0) { ; }; } };
werror("<0 took %fs\n", t);
t = gauge { for(int i=0; i < rpt; i++) { if (has_index(x, elem)) { ; }; } };
werror("has_index() took %fs\n", t);
return 0; }
Sample output on my machine: chromaggus:tools agehall$ pike ~/fun/search_speed.pike 471111 1000000000 Running 1000000000 iterations on array of size 471111 ==-1 took 16.390s <0 took 16.490s has_index() took 16.290s
As you can see, there are no major difference between the three..
__________________________________________________________ Deze e-mail en de inhoud is vertrouwelijk en uitsluitend bestemd voor de geadresseerde(n). Indien u niet de geadresseerde bent van deze e-mail verzoeken wij u dit direct door te geven aan de verzender door middel van een reply e-mail en de ontvangen e-mail uit uw systemen te verwijderen. Als u geen geadresseerde bent, is het niet toegestaan om kennis te nemen van de inhoud, deze te kopieren, te verspreiden, bekend te maken aan derden noch anderszins te gebruiken.
The information contained in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. Please notify us immediately if you have received it in error by reply e-mail and then delete this message from your system. __________________________________________________________