Jump to content

Single Quotes versus Double Quotes


shadowayex
 Share

Recommended Posts

When I first started using PHP about 3 and a half years ago according to this post, I was taught that single quotes performed faster than double quotes most of the time. Lately, I've been reading things that say otherwise. So, I might be a bit out of date on my knowledge. I looked up some tests that seem to confirm that they are indeed almost equal in performance now.My question is this: in large PHP applications, is there a performance difference in using single quotes versus double quotes in general? If not in general, are there cases where a certain type should be used to increase performance? Or is it really just preference nowadays?

Link to comment
Share on other sites

Interesting reading here. You have to scroll to the bottom to find the quotes test. Be sure to refresh a few times, as the numbers are run on the fly. http://www.phpbench.com/
nice. that will be a good lead into starting my work day tomorrow. :) Edited by thescientist
Link to comment
Share on other sites

My question is this: in large PHP applications, is there a performance difference in using single quotes versus double quotes in general? If not in general, are there cases where a certain type should be used to increase performance? Or is it really just preference nowadays?
The difference between single and double quotes with no variables in them is neglectable. It always was, even in versions where it was more noticeable. The difference is less than a milisecond per milion literal strings. Not even large projects use THAT much literal strings (data as vast as that is typically put into a database). So on a realistic scenario, it doesn't really make a difference.The difference between concatenation and double quotes is a little more noticeable though. Last time I did tests (quite a few versions back; could be different now), the difference was ~2ms per milion strings. Still, like I said, even big projects don't use that much literal strings, so in the end of the day, the difference is still neglectable.
Link to comment
Share on other sites

That benchmarking thing it really neat.Yeah, it seems the difference isn't really enough to get too worried about it. Thanks for the responses and the benchmarking site. It was really enlightening.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...