Re: <OPTION

From: Date: Sun, 29 Oct 2006 00:57:36 +0000
Subject: Re: <OPTION
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.general 
Request: Send a blank email to php-general+get-243809@lists.php.net to get a copy of this message
On Sun, 2006-10-29 at 01:32 +0200, Jochem Maas wrote: > Robert Cummings wrote: > > On Fri, 2006-10-27 at 13:51 +0200, Jochem Maas wrote: > >>>>>> range(1, 31) > >>>>> Memory waster ;) > >>>> any idea as to what the damage is as compared to the classic for loop? > >>> Given that a variable probably costs X and that any variable cane be > >>> stored as Y in an array, and an array would cost Z where the Z = X * Y _ > >>> 1 (Y element + 1 for the array container itself). > >>> > >>> Then the range format would cost 31 + 1 (the array itself + 31 entries) > >>> whereas the for loop would cost 1 + 1 (cost to store i + cost to store > >>> endpoint comparison. Thus the damage is about 15*. Given general > >>> computer science consideration, this is a constant and thus practically > >>> neglible. > >>> > >>> Cheers > >>> Rob (ps. the above may be completely incoherent since I'm completely > >>> drunk atm after celebrating two friends birthdays tonight). > >> not a bad explainantion then ;-) it's only the last bit I didn't quite > >> follow :-) > > > > *heheh* It makes sense to me, though my head still hurts from last > > night :) > > > > Which part exactly did you not quite follow? > > this bit: > > Given general computer science consideration, this is a constant and thus practically > neglible. In computer science it's common to profile an algorithm using "Big Oh" notation. In "Big Oh" notation you have: O( Cn ) = O( n ) Where C is a constant multiplier. Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'

« previous php.general (#243809) next »