Re: Re: new function?

From: Date: Tue, 13 Jan 2004 21:47:27 +0000
Subject: Re: Re: new function?
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-7069@lists.php.net to get a copy of this message
Hi, just a correction, I meant array_diff when i wrote array_intersect. array_diff is more handy since just count($res)==0 is enough, $res is the returned array of array_diff(). Andrey Andrey Hristov wrote:
So, I did now some testing. Looks like in_array_all() is 6x faster than array_intersect() the haystack is 10 elements, and needles are 3. When 1000 elements in haystack, the fastest time (when the needles are in the beggining in_array_all is 300x faster. When the whole haystack should be traversed it's about 250x faster than array_intersect. When one of the needles is not in the haystack : 300x . Script : <?php $i = 0; while ($i++ < 1000) {
        $a[] = $i;
} $start = microtime(1); $res = in_array_all(100, 2, 3, $a, true); $end = microtime(1); printf("Time : %3.5f\n",$end - $start); $needles = array(100, 2, 3); $start = microtime(1); $diff = array_diff($needles, $a); $end = microtime(1); var_dump($diff); printf("Time : %3.5f\n",$end - $start); ?> andrey@poohie:~/dev/5_0> ./php s.php bool(true) Time : 0.00010 array(0) { } Time : 0.03888 Andrey


« previous php.internals (#7069) next »