Sie sind hier : sebastian1012.bplaced.net/ homepage-neu / kreuz-und-quer / tutorials-info-neuigkeiten-php / 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 mein Code-Schnipsel, in dem ich je nach Test das „echo“ durch „print“ bzw das “ durch ‚ ersetzt habe. Ich habe bewusst nicht alles in ein Testscript geschrieben, weil ich festgestellt hatte, 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 '<br />'.(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

Ich konnte 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 hatte).