String Theory

Tweet

The other day I found myself in an argument about whether or not a single quoted string was faster than a double quoted string. I know that there are conventions that dictate the use of one over the other for clarity, but I was curious to see if there was actually a performance component. I being on the side of the single quoted string(SQ) thought surely since SQ strings aren't interpolated they'd be loads faster. Unfortunately, proving myself right was not as easy as I had initially thought.

Define the parameters

The first thing I needed to do to prove my point was to define how we would measure and quantify success of one string over the other. We came up with these criteria:

The positive difference must be statistically significant. The test must be consistent. The sample size must be ample enough to account for any external factors.

The results

Right out of the shoots you can see that there is actually very little difference. I found that single quoted strings were about ~0.19% faster than double quoted strings. This is hardly the victory I was hoping for. The difference was more pronounced in jruby, but the test was significantly more erratic.

Anyways, I won right? Wrong! Let's move onto the methodology and dig into why it might still be too early to bust out the ticker tape.

Methodology