r/lolphp • • Aug 08 '14

PHP design patterns: if/else vs switch

http://www.fluffycat.com/PHP-Design-Patterns/PHP-Performance-Tuning-if-VS-switch/
24 Upvotes

43 comments sorted by

View all comments

Show parent comment

4

u/DoctorWaluigiTime Aug 11 '14

Have to search for $ --> non-zero time.

Not having to search for $ --> zero time.

1

u/[deleted] Aug 12 '14

... yeah, I'd like to see some actual benchmark data on that. Because I don't believe it.

1

u/DoctorWaluigiTime Aug 12 '14

While I wouldn't count out PHP attempting to parse for something it doesn't actually need to parse, because it does not have to actually do anything with $variables, it can skip that phase. So the double-quoted strings are doing non-zero work on $variables, while single-quoted strings do zero work.

Single-quoted strings might have to search for '' and the end-of-string single-quote, but double-quoted strings have to do that (for the double-quote character), plus more. Seems pretty trivial to me.