Echo Is Faster Than Print [TotD]

Posted by hts | January 4, 2008 .

Here’s a quick one: use echo when you output content, since it is faster that print.

Why is that? print() is a function, in fact and therefore it takes more time to process it.

So unless you have to output formatted content (in which case you’d use sprintf(), for example), just use echo. It is faster - and simpler.

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

3 Comments so far
  1. Dave January 8, 2008 10:49 pm

    Everywhere else I have read that print is faster than echo. This includes the comments section of php.net.

    Have you actually done any benchmarks to test this assertion ?

    Incidentally, using single-quote strings is much faster than double-quote strings. The difference there is that double-quote strings are parsed for variables at run time.

  2. hts January 9, 2008 1:36 pm

    Hmm.. I’ve read this somewhere, some long time ago, and since then, I’ve been using echo to output content in all my scripts. I’ll have to dig deeper for this problem. If I’m wrong, all my apologies, to Dave and all my readers - and thanks for noticing.

  3. Wunar January 13, 2008 8:03 am

    Just use whichever one you prefer, and whichever seems more appropriate and readable, as you won’t notice any difference, especially if eaccelerator / zend optimizer / any other bytecode optimizer comes into play (and it should, if you’re concerned with performance).