biggest difference:

http://php.net/print
print() returns 1, always - which means it's returning a value

http://php.net/echo
doesn't return anything

Sara Golemon's "how long is a piece of string" blog post
(http://blog.libssh2.org/index.php?/archives/28-How-long-is-a-piece-of-string.html
which appears to be down or something right now) I believe shows the
different opcodes (using VLD - http://pecl.php.net/package/vld)

This is a micro-level optimization. I believe echo is "faster" or
"less intensive" because it does not need to return a value, but on
modern CPUs saving a couple ops is probably not that big of a deal
(even thousands of them) - I think the general consensus is "there is
really no difference" last I saw. Only very very small optimizations.

On Wed, Jun 30, 2010 at 10:22 AM, Jim Lucas <li...@cmsws.com> wrote:
> Brandon Rampersad wrote:
>> Hello guys, i was just doing some testing and was wondring if echo is faster
>> than print or print_r. I think since echo is a language construct and
>> print_r is a function, echo is faster.
>>
>> Please let me know.
>>
>> Thanks
>>
>
> People in the past have said that echo and print as actually the same call
> within PHP core system.  I have never dug through the core code that makes up
> PHP so I cannot confirm this claim.
>
> print_r on the other hand is a totally different thing.  It takes and 
> processes
> strings, arrays, objects, etc... So, with that said, it will be much slower.  
> It
> has to detect what type of object it is and then deal with all the pieces.  
> And
> then in the end, output everything to the screen.
>
> --
> Jim Lucas
>
> A: Maybe because some people are too annoyed by top-posting.
> Q: Why do I not get an answer to my question(s)?
> A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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

Reply via email to