According to a quick benchmark on my machine (MacBook Air 2013, Ruby
2.1.0p0), using double quotes is about 2% faster:

    require 'benchmark'

    n = 10_000_000
    Benchmark.bm do |x|
      x.report { n.times do ; a = "1"; end }
      x.report { n.times do ; a = '1'; end }
    end

       user     system      total        real
   1.020000   0.000000   1.020000 (  1.015903)
   0.990000   0.000000   0.990000 (  0.992175)

However, as you can see it takes about 1 second to do 10 million
iterations, so in reality, using a " instead of a ' adds on about 2
nanoseconds on a 99 nanosecond operation.  There are much bigger
inefficiencies in all of our code than worrying about saving the odd 2ns
here and there...

I personally tend to use double quotes everywhere, for the same reason that
I never do if statements on multiple lines (in Javascript for example)
without braces.  I'd much rather have the almost unmeasurable wastage than
risk a bug.

Cheers,


Andy

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CANRNWfgF%3Dpht4dRE1od0y1g%2BHubjbKtfBDo9WiYz6yTeLB%2BV6A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to