Menu:

Delicious!

arrow Drawing with jquery

arrow Mobile applications RIP

arrow Lighthttpd tuning

arrow Kännykästä WLAN tukiasema

arrow MySQL advanced performance tips

 left_thumb_25102008-002.jpgleft_thumb_24102008-032.jpgleft_thumb_24102008-015.jpgleft_thumb_24102008-013.jpgleft_thumb_20092008.jpg 

Dezign
(4 Janv, 2007)

PHP's different echo methods performance comparison.

Posted on 2007-12-08 13:45:46 EET.

Some times I've been told that don't use double quotes with echo since it's a bit slower. I've sometimes read some discussion about this issue and most of the time the debate has been more or less speculation based.

First time I found that someone has actually made a real test for this issue. Well the test is a year and a half old and it does not give any info about the system it was run on.

I did the same test in a machine that is running debian etch and php 5.2 without bytecode cache. Results where followin

Benchmark: send to page

   No concatenation
single quotes (655 ms)
double quotes (241 ms)
heredoc (833 ms)
printf (290 ms)
   With concatenation
single quotes (540 ms)
double quotes (367 ms)
heredoc (316 ms)
printf (290 ms)

Benchmark: send to output buffer

    No concatenation
single quotes (4 ms)
double quotes (4 ms)
heredoc (295 ms)
printf (46 ms)
   With concatenation
single quotes (33 ms)
double quotes (45 ms)
heredoc (44 ms)
printf (31 ms)

And then I tried the same test in a machine where PHP bytecode cahce was turned on. Result are below

Benchmark: send to page

    No concatenation
single quotes (288 ms)
double quotes (262 ms)
heredoc (280 ms)
printf (308 ms)
    With concatenation
single quotes (556 ms)
double quotes (355 ms)
heredoc (436 ms)
printf (274 ms)

Benchmark: send to output buffer

   No concatenation
single quotes (8 ms)
double quotes (4 ms)
heredoc (4 ms)
printf (53 ms)
    With concatenation
single quotes (39 ms)
double quotes (16 ms)
heredoc (13 ms)
printf (31 ms)

Well one conclusion can be made. Double quotes are not as bad as you except in performance. Probably the PHP site's test was made with PHP 4. And in my opinion double quotes can improve code maintability and readibility when used in right manner. Printf is slow, but thats because it has some logic, for example rounding float numbers. If you need to echo rounded values the printf could be a sufficent solution. Then you dont have to do floor or round calls to your numbers.

If someone wishes to try the script with PHP4 to get different numbers, the script is available at here.

Back