1

Possible Duplicate:
What is the best way to add two strings together?

Ignoring the data formatting benefits, which of these is the quickest? Or less memory hungry?
I expect the difference to be negligible.

$answer = "A String: {$string}";

$answer = sprintf('A String: %s', $string);

PS: I read a blog that discovered echo $a, $b was slightly faster than echo $a . $b (comma vs concatenate) because the latter creates a third value temporarily before echoing it.

Community
  • 1
  • 1
clockworkgeek
  • 37,650
  • 9
  • 89
  • 127
  • 6
    The important answer is, "it doesn't matter". Use whichever one produces cleaner code. If you still care about performance, which you absolutely shouldn't, See http://www.phpbench.com/ – user229044 Dec 10 '10 at 19:29
  • 2
    This and the related "single-vs-double quotes" argument have been debated ad nauseum: [What is the best way to add two strings together?](http://stackoverflow.com/questions/695124/what-is-the-best-way-to-add-two-strings-together) – user229044 Dec 10 '10 at 19:31
  • Better duplicate: http://stackoverflow.com/questions/3316060/php-single-quotes-or-double-quotes-for-variable-concatenation – user229044 Dec 10 '10 at 19:35
  • @meagar The phpbench examples are interesting but look a bit flawed to me. None of the syntax case measurements subtracts the time spent on the for-loop. While the last test, which is testing loops, is completely empty and thus has little resemblence to real-world code. – mario Dec 10 '10 at 19:49
  • I didn't mean to distract with discussion of concatenation which is why I put it as a PS. Really I'm interested in the parsing speed, not which is "best" or "worthwhile". – clockworkgeek Dec 10 '10 at 20:00

0 Answers0