Performance differences between Single Quotes and Double Quotes in PHP

Realistically speaking, there are none. No, seriously. If you want my advice, you should just cut the micro-optimization crap and focus on writing clean and readable code that abides by best practises. Obsessing over small and insignificant things like this will do you no good! I’ve said it before and I’ll say it again: If you’re at the point where these kind of optimizations affect the performance of your application, then something is seriously rotten in the state of Denmark!

Why it doesn’t matter.

  • I’ve yet to see a modern benchmark that shows any recognizable differences. In most cases, the results are old or remarkably inconclusive. That, or the differences are so small and minute that it would be ridiculous to take them seriously.
  • Even if it did matter (it doesn’t) – In most production environments, you should be using a bytecode cache such as OPcache or APC.
  • In the past, some of the developers behind PHP have rejected the notion that there are any performance gains to be had by selectively choosing Single Quotes over Double Quotes.
  • If there isn’t a variable in the double-quoted string, they will both generate the exact same opcode.
  • There are much bigger “bottlenecks” to worry about. Database connections, queries, searching large and complex arrays; for example.

All in all, I think it is ridiculous that so many “help” articles perpetuate the myth that this is something that a developer needs to worry about.

Comments

comments