0

I'm writing some really time sensitive production application that suppose to serve millions of customers.

the server side is written in php and has some files with around 200 predefined strings with a length of around 5 to 25 characters that are all double quoted without any variables in them. for example:

 define("DEFCON_ONE", "id");
 define("DEFCON_TWO", "name");
 .......

does changing these strings from double quote to single quotes really saves some cpu cycles because the php interpter won't search for \n or variables in it ?

these applications are really time sensitive so if this is the case I'll go and change each file and each line of code but I just want to be sure before I go and change everything.

thank you.

ufk
  • 30,912
  • 70
  • 235
  • 386
  • 1
    You might want to read this question : http://stackoverflow.com/questions/3446216/difference-between-single-quote-and-double-quote-string-in-php – koopajah Feb 05 '13 at 11:37
  • I'd look into [Facebook's HipHop](https://github.com/facebook/hiphop-php/wiki) if the application will be *that* sensitive to load – Zathrus Writer Feb 05 '13 at 11:39
  • 1
    Yes, in _some_ most likely quite synthetic cases you will be able to _measure_ a difference, however as @ZathrusWriter mentions above, there is much to do that will gain much more time than that very optimization. For example, APC/Hiphop/SSD disks or simple algorithm optimizations will make a difference that is not just measurable but most likely quite noticeable. Start there. – Joachim Isaksson Feb 05 '13 at 11:47
  • You can also read: http://stackoverflow.com/questions/482202/is-there-a-performance-benefit-single-quote-vs-double-quote-in-php – Alvaro Feb 05 '13 at 11:52
  • I sometimes glance over at http://www.phpbench.com/ (double (") vs. single (') quotes section) whilst interesting, I do not take the results as the definitive answer. – DrBeza Feb 05 '13 at 12:02

2 Answers2

0

The performance hit is negligible if it even exists. It is said single quotes are faster because anything contained within it is not parsed for variables, or special characters. WHere as double quotes parses special characters and variables. For example:

$var = 'world';

echo 'hello\n$var';

echos:
hello\n$var

echo "hello\n$var";

echos
hello
world

Personally, if you are not using special characters or variables in your string, stick to single quotes, else just use double quotes. But performance should not be a worry on this. Premature optimisation my friend.

Ozzy
  • 10,285
  • 26
  • 94
  • 138
0

In a micro optimization way, yes.

Double quotes force PHP to parse it even if there aren't variables inside the string.

But don't worry, we have a lot of ways to optimize our code before to attack micro optimizitaion :)

corretge
  • 1,751
  • 11
  • 24