Sie sind hier : sebastian1012.bplaced.net/ homepage-neu / kreuz-und-quer / echo-mit-oder-was-ist-schneller.php

echo mit “ oder ‚ – was ist schneller?

Dieser Artikel ist (nicht) nur für Ulf, der in seinem letzten Kommentar meinte:

echo oder print, “ oder ‚ machen nun wirklich keinen bemerkenswerten Performanceunterschied aus

Ob das stimmt habe ich dann mal genauer untersucht. Hier ein Code-Schnipsel, in dem je nach Test das „echo“ durch „print“ bzw das “ durch ‚ ersetzt wurde. Es wurde bewusst nicht alles in ein Testscript geschrieben, weil festgestellt gewurde, dass immer die Tests, die im hinteren Teil des Scripts standen unglaubwürdig lange gebraucht hatten:

$t=microtime(true); for ($x=0;$x<1000;$x++)   {   
echo "JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ 
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ 
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ 
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ 
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ 
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ 
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ 
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ 
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ 
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ 
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ 
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ 
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ"; 
} echo '
'.(microtime(true)-$t).' s';

Ergebnis:

Echo und „: ca. 2,5s
Echo und ‚: ca. 2,1s
Print und „: ca. 2,5s
Print und ‚: ca. 2,1s

Fazit

Mam kann keinen Performance-Unterschied zwischen Print oder Echo feststellen. Der Unterschied zwischen “ und ‚ ist auf jedenfall vorhanden – wenn auch nicht groß (Man darf nicht vergessen, dass ich zum Testen einen Extremfall (extrem viel Text) verwendet wurde).