Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:7069 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76119 invoked by uid 1010); 13 Jan 2004 21:48:53 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 76085 invoked from network); 13 Jan 2004 21:48:52 -0000 Received: from unknown (HELO stella.fastforwardnetwork.com) (209.51.153.50) by pb1.pair.com with SMTP; 13 Jan 2004 21:48:52 -0000 Received: (qmail 15873 invoked from network); 13 Jan 2004 22:53:18 -0000 Received: from p508aa864.dip.t-dialin.net (HELO hristov.com) (80.138.168.100) by d.goto.bg with SMTP; 13 Jan 2004 22:53:18 -0000 Message-ID: <4004676F.8010803@hristov.com> Date: Tue, 13 Jan 2004 22:47:27 +0100 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20031230 X-Accept-Language: en-us, en MIME-Version: 1.0 To: internals@lists.php.net References: <40045BB4.4050000@hristov.com> <40046198.6010800@cschneid.com> <400466AB.2020502@hristov.com> In-Reply-To: <400466AB.2020502@hristov.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: new function? From: php@hristov.com (Andrey Hristov) 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 : > > $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 >