the print() stuff is minimal.  You are just copying stuff to the buffer.
If you were outputting to a file when your way is faster.

It has to do with the fact that in the while you keep leaving the array.
and check the while, in the php layer.

In the foreach do the same thing just on the c layer.  You save that bit
of time because you do not have to go out to the php engine and parse again.

Rick



At 08:20 AM 3/14/01 -0800, Dennis Gearon wrote:
>I meant to write about this last week!
>
>I see a LOT of examples on the PHP website, both by contributions and by
>the staff responsible for the manual, of using functions inside of loops
>to get a value that doesn't change, i.e. the end or beginning of an
>array.
>
>A lot of code out there would speed up tremendously if the necessary
>value was stored in a temporary variable, which would then be used in
>the loop. Probably, using echo() or print() in a loop also slows things
>down, buffering into a variable first is much faster, I bet.
>
>One thing I've taken to doing that is related to this, is any object
>method() that would normally have a printed output, I make two output
>functions, 'getValue()' and 'printValue()'. the getValue() buffers to a
>variable in the object and this can be used inline in another place
>thats buffering output. If I want it printed right away, the
>printValue() calls getValue().
>
>And because I like readable web page HTML, I also have begun to start
>including an 'indention' argument to those functions, or sometimes an
>'indention' attribute. At the beginning of the buffering and also
>following a '\n' in the HTML being buffered, I place the number of
>spaces to cause proper indention in the HTML output to make tables etc
>line up. It does make the files a little bigger, but it's lot's easier
>to see what's going on in the code. I suppose if I wanted to, I could
>make a global variable that said, 'INDENTION_ON/OFF' for production.
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]

##########################################################
#  Rick St Jean,
#  [EMAIL PROTECTED]
#  President of Design Shark,
#  http://www.designshark.com/
#  Quick Contact:  http://www.designshark.com/messaging.ihtml
#  Tel: 905-684-2952
##########################################################


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to