Re: PHP 4.0 Bug #6608: sizeof($array) extremly slow in loop. 90% cpu util

From: Date: Thu, 07 Sep 2000 17:11:09 +0000
Subject: Re: PHP 4.0 Bug #6608: sizeof($array) extremly slow in loop. 90% cpu util
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-32589@lists.php.net to get a copy of this message
Hi, mledet@spirenet.com wrote: > From: mledet@spirenet.com > Operating system: Linux 2.2.16 > PHP version: 4.0.2 > PHP Bug Type: Arrays related > Bug description: sizeof($array) extremly slow in loop. 90% cpu util > > The following code performed well under 3.0.16. > for ($i=0; $i < sizeof($teacherarray); $i++) { > $a=$teacher_array[$i]; > if ($a->teacher_id==$teacher_id) { > break; > } > } > However, under php 4.0.2 it is extrememly slow and causes cpu util for the httpd process to hit > 90%. $teacherarray is not being modified during the loop so the condition isn't changing. It is not changing, but the size of the array is evaluated every time. This is a not so good codingstyle I think. > > > BTW: Changing to the following code works ok. > > $numteachers = sizeof($teacherarray); > for ($i=0; $i < $numteachers; $i++) { > $a=$teacher_array[$i]; > if ($a->teacher_id==$teacher_id) { > break; > } > } > This piece of code is preferred, but now the size evaluation always finds place only one time. Regards, -- Derick Rethans JDI Media Solutions H.v.Tussenbroekstraat 1 6952 BL Dieren The Netherlands e-mail: d.rethans@jdimedia.nl http://www.jdimedia.nl/

« previous php.dev (#32589) next »