Re: More microptimisation (Was Re: [PHP] Variable as an index)

From: Date: Tue, 23 Dec 2008 06:43:30 +0000
Subject: Re: More microptimisation (Was Re: [PHP] Variable as an index)
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.general 
Request: Send a blank email to php-general+get-284995@lists.php.net to get a copy of this message
2008/12/22 German Geek <geek.de@gmail.com>: > agree, ++$i wont save u nething, it just means that the variable is > incremented after it is used: You meant ". . .before it is used:", right? Torben > $i = 0; > while ($i < 4) echo $i++; > > will output > 0123 > > while > > $i = 0; > while ($i < 4) echo ++$i; > > will output > 1234 > > Tim-Hinnerk Heuer > > http://www.ihostnz.com > > > On Tue, Dec 23, 2008 at 7:25 PM, Nathan Nobbe <quickshiftin@gmail.com>wrote: > >> On Mon, Dec 22, 2008 at 3:10 PM, Clancy <clancy_1@cybec.com.au> wrote: >> >> > On Mon, 22 Dec 2008 10:20:09 +1100, dmagick@gmail.com (Chris) wrote: >> > ............ >> > >I'd call this a micro-optimization. If changing this causes that much of >> > >a difference in your script, wow - you're way ahead of the rest of us. >> > >> > Schlossnagle (in "Advanced PHP Programming") advises: >> > >> > $i = 0; while ($i < $j) >> > { >> > ........ >> > ++$i; >> > } >> > >> > rather than: >> > >> > $i = 0; while ($i < $j) >> > { >> > ....... >> > $i++; >> > } >> > >> > as the former apparently uses less memory references. However I find it >> > very hard to >> > believe that the difference would ever show up in the real world. >> >> >> nonsense, some college kid is going to put ++$i on a test to try an impress >> the professor when the semantics call for $i++ :D >> >> -nathan >> p.s. >> in case you couldnt tell; been there, done that. lol >> > -- Torben Wilson <torben@2powerweb.com>

« previous php.general (#284995) next »