Re: Print or Echo takes lots of time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Google Kreme wrote:
> On 25 Sep 2006, at 06:11 , Sancar Saran wrote:
> ...
> 
> If this is generating hundred of K of HTML, use ' instead of "
> 
> (yes, it's faster).
> 

I've seen this stated several times and at first glance it seems to make
sense.  The double quoted version has all the \n and related characters
that need to be handled.

Except that php is a C program and uses the printf family of functions.
 This means that all the single quoted strings actually have to be
converted to escaped versions of double quoted strings, so internally
'\n' becomes "\\n".

You can see this in some benchmarks, I ran the following script and a
single quoted version from the command line.  I ran each 10 times,
interleaved to try to balance changes in the system load.

<?php
$str="";
for($i=0; $i<10000000; $i++)
        $str.="foo";
?>

I found that the double quoted version averaged 5.5516 seconds against
the single quoted script of 5.5627.  Which really goes to show that
while the double quoted version is faster the difference is almost
completely irrelevent.


David

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux