Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:16591 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1834 invoked by uid 1010); 10 Jun 2005 07:54:58 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 1819 invoked from network); 10 Jun 2005 07:54:58 -0000 Received: from unknown (HELO gmail.com) (127.0.0.1) by localhost with SMTP; 10 Jun 2005 07:54:58 -0000 X-Host-Fingerprint: 64.233.184.195 wproxy.gmail.com Linux 2.4/2.6 Received: from ([64.233.184.195:24287] helo=wproxy.gmail.com) by pb1.pair.com (ecelerity 1.2 r(5656M)) with SMTP id B1/8E-21296-05749A24 for ; Fri, 10 Jun 2005 03:54:56 -0400 Received: by wproxy.gmail.com with SMTP id 49so47594wri for ; Fri, 10 Jun 2005 00:54:53 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=Bo4BAEHipV+JxQRuCuRqztV5yZdJHOVRsMgnYDB8KK+m1RNwXxOQ62g0QxYYFStIWy/wRjZKP8RAsaaXoMUQAEyH9ctAzoriHcQL0b4usvhtZoarw0GCImuUPxJxWIDYZjuZ7lltAAz/W+guA6mIJusZHqdIrLmkGFhwjCVRNPc= Received: by 10.54.17.28 with SMTP id 28mr90745wrq; Fri, 10 Jun 2005 00:54:53 -0700 (PDT) Received: by 10.54.20.24 with HTTP; Fri, 10 Jun 2005 00:54:53 -0700 (PDT) Message-ID: <28139bc05061000547cfc827d@mail.gmail.com> Date: Fri, 10 Jun 2005 15:54:53 +0800 Reply-To: Xuefer To: internals@lists.php.net Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Subject: strange php4.3.x foreach performance issue From: xuefer@gmail.com (Xuefer) "foreach ($arr as $k =3D> $v)" is 2 times as faster as "foreach ($arr as $v)" in php4.3.x both test under lastest cvs. 4.3.12-dev testing with array[] =3D string $v: 2.5590002536774 $k=3D>$v: 0.7020001411438 $v each(): 1.025000333786 $k $v each(): 1.1790001392365 testing with array[] =3D array(string) $v: 0.50299978256226 $k=3D>$v: 0.70599985122681 $v each(): 0.9909999370575 $k $v each(): 1.172000169754 5.1.0-dev testing with array[] =3D string $v: 0.15599966049194 $k=3D>$v: 0.19999980926514 $v each(): 0.78099966049194 $k $v each(): 0.77299976348877 testing with array[] =3D array(string) $v: 0.16900014877319 $k=3D>$v: 0.19900012016296 $v each(): 0.71399998664856 $k $v each(): 0.77100014686584 $v) $dummy =3D $v; } echo '$k=3D>$v:', "\t", stopwatch() - $extra, "\n"; stopwatch(); for ($i =3D 0; $i < $count; $i ++) { $r =3D $arr; reset($r); while (list(, $v) =3D each($r)) $dummy =3D $v; } echo '$v each():', "\t", stopwatch() - $extra, "\n"; stopwatch(); for ($i =3D 0; $i < $count; $i ++) { $r =3D $arr; reset($r); while (list($k, $v) =3D each($r)) $dummy =3D $v; } echo '$k $v each():', "\t", stopwatch() - $extra, "\n"; } echo PHP_VERSION, "\n"; echo "testing with array[] =3D string\n"; $arr =3D array(); for ($i =3D 0; $i < 100; $i ++) { $arr[] =3D str_repeat('-', 10240); } runtest($arr); echo "testing with array[] =3D array(string)\n"; $arr =3D array(); for ($i =3D 0; $i < 100; $i ++) { $arr[] =3D array(str_repeat('-', 10240)); } runtest($arr); echo "testing with queryAll\n"; [quote: http://ez.no/community/blog/foreach_performance_improvement_backpor= t] This patch improves performance with foreach() where the key of the array element is not interesting (for example foreach($array as $value); ). [/quote]