On Thu, Aug 16, 2012 at 4:23 PM, ajay paswan <[email protected]> wrote: > Robert Klemme wrote in post #1072532: >> On Thu, Aug 16, 2012 at 1:43 PM, ajay paswan <[email protected]> >> wrote: >>> Which one is faster? >> >> Measure it. There is Benchmark. >> > means? what measure? and who'll measure?
You want to know which one is faster so you'll measure it. require 'benchmark' Benchmark.bm do |b| ... end http://www.ruby-doc.org/stdlib-1.9.3/libdoc/benchmark/rdoc/index.html >> SMARTNESS = { >> "A" => "you are smart", >> "B" => "you are dumb", >> } > is it mapping? looks like one. It's a Hash stored in a constant. A hash lookup is typically quite fast compared to control flow - especially if you increase the number of alternatives. But: measure it! >> puts SMARTNESS[grade] >> >> Cheers >> >> robert > > Whats that What? That's my name. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ -- You received this message because you are subscribed to the Google Groups ruby-talk-google group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at https://groups.google.com/d/forum/ruby-talk-google?hl=en
