[TYPO3-core] RFC #12066: Code cleanup: Add some constants

Sigfried Arnold s.arnold at rebell.at
Wed Mar 3 18:18:39 CET 2010


Am 03.03.2010 17:51, schrieb Steffen Ritter:
> \n is bad to read.
> "" is slower than ''

Stating double quotes are slower than single quotes is a common mistake. 
Double quotes are faster, but the difference is very insignificant.

Examples:
http://www.phpbench.com/ - section: double (") vs. single (') quotes
http://benchmark.nophia.de/benchmarks-textverarbeitung-k-2-single-quotes-oder-double-quotes-teil-1-b-3.html
http://phpperformance.de/gaensefuesschen-oder-hochkomma/

BUT: using variables in double quoted strings is slower than using 
string concatenation - since you cannot use variables in single quoted 
strings you cannot compare it directly, but used proper, double quotes 
are still faster.

echo $foo . "bar"; is faster than echo "$foo bar";
echo $foo . "bar"; is faster than echo $foo . 'bar';

But as stated before: the time difference is insiginficant and not 
notable at all - if performance should be really raised, you could use a 
PHP bytecache like eAccelerator or ZendOptimizer.

Additional:
A function call to chr(10) is slower than using double quoted "\n".
Referencing to a constant is slower than using no variable or constant 
out of global scope at all - so "\n" is faster.

You can benchmark that all by yourself by using the benchmark tool at 
nophia.de.

Last notes:

I prefer single quotes though i know, they are slower :p


More information about the TYPO3-team-core mailing list