Here are the results of the above benchmark running against three different Ruby VMs.
ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-darwin11.4.0]
user system total real
single 0.170000 0.000000 0.170000 ( 0.171696)
double 0.170000 0.000000 0.170000 ( 0.171394)
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
user system total real
single 0.190000 0.000000 0.190000 ( 0.189292)
double 0.180000 0.000000 0.180000 ( 0.184996)
jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_35) [darwin-x86_64-java]
user system total real
single 0.420000 0.010000 0.430000 ( 0.221000)
double 0.240000 0.010000 0.250000 ( 0.118000)
As you can see, double quotes are actually faster in all three VMs. They are twice as fast in JRuby but only marginally faster in the two CRuby VMs. I don't have Rubinius on hand or I'd test that as well.
So, there you have it. Double quotes interpolate strings easily, support several nifty escape sequences like \n
and \t
, and for whatever reason they're faster than their counterpart. Maybe because there's 2X the quotes!
ruby 2.4.1
if double quotes has interpolation
single 0.070000 0.000000 0.070000 ( 0.071082)
double 0.080000 0.000000 0.080000 ( 0.079633)