On 17 March 2014 14:13, Andy Jeffries <a...@andyjeffries.co.uk> wrote:
> According to a quick benchmark on my machine (MacBook Air 2013, Ruby
> 2.1.0p0), using double quotes is about 2% faster:

Or, possibly, slower.

>
>     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)

Did you try swapping the two lines round and checking that the result
is consistent?

Colin

>
> 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...

-- 
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/CAL%3D0gLveoiq5ypjLd-Cb5kQproRDwLp6%2BQ6%3DpPZ-FtioJ-sG4A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to