To make it clear: as stated by bigown and Guilherme , there are many other factors that influence performance more than this detail. If you have performance issues in your project, that will not save you .
Out of curiosity, using the site 3v4l.org , I ran some tests.
Test 1 - echo
with multiple constant values ( link )
echo "Anderson", "Carlos", "Woss";
The performance result can be seen in different versions of PHP below:
BycheckingtheOPCodesanalysisprovided,wehave:
FindingentrypointsBranchanalysisfromposition:0Jumpfound.(Code=62)Position1=-2filename:/in/e38n0functionname:(null)numberofops:4compiledvars:noneline#*EIOopfetchextreturnoperands-------------------------------------------------------------------------------------30E>ECHO'Anderson'1ECHO'Carlos'2ECHO'Woss'3>RETURN1
Thatis,whenexecutedinthisway,whatactuallyhappensisthecalloftheecho
statementthreetimes,eachwithaparameter.
Test#2-echo
withconcatenationofconstantvalues( link )
echo "Anderson"."Carlos"."Woss";
The performance result can be seen in different versions of PHP below:
BycheckingtheOPCodesanalysisprovided,wehave:
FindingentrypointsBranchanalysisfromposition:0Jumpfound.(Code=62)Position1=-2filename:/in/hQmo3functionname:(null)numberofops:2compiledvars:noneline#*EIOopfetchextreturnoperands-------------------------------------------------------------------------------------30E>ECHO'AndersonCarlosWoss'1>RETURN1
WhatseemstohappeninthiscaseisthePHPinterpreteralreadyconcatenatingthevaluesbeforethecodeisexecuted,thenthe
echo
statementiscalledonlyonce,withthefinalstring.Thisisbecausethepastvaluesareconstantandtheinterpretercandosuchoptimization(ifitcanbecalledthatway).
Test#3-echo
withmultiplevalueswithvariable( link )
$nome = "Anderson";
echo "Bem vindo, ", $nome;
The performance result can be seen in different versions of PHP below:
BycheckingtheOPCodesanalysisprovided,wehave:
FindingentrypointsBranchanalysisfromposition:0Jumpfound.(Code=62)Position1=-2filename:/in/N4IMIfunctionname:(null)numberofops:4compiledvars:!0=$nomeline#*EIOopfetchextreturnoperands-------------------------------------------------------------------------------------30E>ASSIGN!0,'Anderson'51ECHO'Bem+vindo%2C+'2ECHO!03>RETURN1
Againweseethatwhathappensinfactistheduplicatecallofecho
,onewiththeconstantvalue,anotherwiththedefinedvariable.
Test#4-echo
withconcatenationwithvariable( link )
$nome = "Anderson";
echo "Bem vindo, ". $nome;
The performance result can be seen in different versions of PHP below:
BycheckingtheOPCodesanalysisprovided,wehave:
FindingentrypointsBranchanalysisfromposition:0Jumpfound.(Code=62)Position1=-2filename:/in/FfLnCfunctionname:(null)numberofops:4compiledvars:!0=$nomeline#*EIOopfetchextreturnoperands-------------------------------------------------------------------------------------30E>ASSIGN!0,'Anderson'51CONCAT~2'Bem+vindo%2C+',!02ECHO~23>RETURN1
Nowhavingavariableinvolved,wecanseethattheprevious"optimization" process is no longer possible, so the call of the concatenation operator is actually occurring.
I do not know how much of this data can be conclusive, but you can see that the concatenation process was faster than multiple echo
calls when multiple comma-separated values were passed.