Re: echo or print ?

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

 



On 4/18/07, Richard Lynch <ceo@xxxxxxxxx> wrote:
On Tue, April 17, 2007 1:40 am, Christian Haensel wrote:
> Whenever I see people put their code up for review, I realize they
> mostly
> use print instead of echo, while I am using echo 99% of the time.
> Actually,
> I can't even remember when I last used the regular print.

There used to be a difference, but not really any more, I don't think.

Or does print still not allow multiple arguments?...

> What do you guys use, and what is the advantage (if ther is any) of
> print
> over echo? And I am not talking about print_r or anything, just the
> regular
> print. :o)

I use echo, because I'm old, and got in the habit, back when print()
was a function and echo was a language construct, and only echo let
you have as many args with commas as you wanted.

But there's no significant difference, as far as I know.

There is a difference, echo is slightly faster.
code used for benchmark:
<?
$start = microtime(TRUE);
for ($i=0; $i<100000; ++$i) { print "ABC"; }
echo sprintf("With print ($i): %0.3f\n",microtime(TRUE) - $start);
$start = microtime(TRUE);
for ($i=0; $i<100000; ++$i) { echo "ABC"; }
echo sprintf("With echo ($i): %0.3f\n",microtime(TRUE) - $start);
?>

it displays 100000 times ABC, first with the print command, and second
with the echo command. Result:
ABCABCABC<snip>
print (100000): 0.085
ABCABCABC<snip>
echo (100000): 0.076


It's not a lot, but since we are displaying data a lot, (most used
function?) it will make a difference in really big scripts.

Tijnema


--
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