Prev: Is this a bug with date() ?
Next: Past discussion
From: Brandon Rampersad on 30 Jun 2010 13:07 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 -- A Brandon_R Production
From: Jim Lucas on 30 Jun 2010 13:22 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?
From: Robert Cummings on 30 Jun 2010 13:38 Hey Brandon, do you think you could spend some time reading the Google talk manual? It's kind of irritating seeing your "Brandon Rampersad wants to chat" spam on the list repeatedly. As for which is faster... your assertion is right. Cheers, Rob. 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 > -- E-Mail Disclaimer: Information contained in this message and any attached documents is considered confidential and legally protected. This message is intended solely for the addressee(s). Disclosure, copying, and distribution are prohibited unless authorized.
From: Michael Shadle on 30 Jun 2010 14:02 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 <lists(a)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 > >
|
Pages: 1 Prev: Is this a bug with date() ? Next: Past discussion |