3 ms·
There is zero performance difference between single quoted strings and double quoted strings with no interpolation.
by anamexis 6y ago
There is zero performance difference between single quoted strings and double quoted strings with no interpolation.
- fomine3 6y agoTheoretically parsing "" should have very little overhead only on parsing, but parsing string is tiny work so it can't be problem. Anyway who cares such performance won't use Ruby.
- Lio 6y agoThat's interesting. I was told about a ruby project years ago where they gained a measurable performance boost by converting all the strings without interpolation to single quotes. That's a vague anecdote so should be taken with a pinch of salt. Even if it was once the case VM often improve to fix these edge cases. So I was just wondering if there was anything more formal to prove this so that I can avoid this preconception I've been carrying around for years based on nothing more than someone's now dated Lightning Talk.
- anamexis 6y agoHere's a good summary by someone on StackOverflow, with links to Ruby source: https://stackoverflow.com/a/1836838/2850811 https://stackoverflow.com/a/1836838/2850811
- Lio 6y agoThanks for the reply. It seems that any cost is small and at parse time rather than runtime. That seems like a good enough reason to always use double " for consistency to me.