From: Robert Klemme Date: 2009-11-26T01:29:00+09:00 Subject: Re: Ruby internals & other questions 2009/11/25 Ralph Shnelvar : > Is there a document or website that describes how Ruby works? > > For instance ... > > > > y=0 > 1_000_000.times {|x| y+=x} > > > > (1) Does the block get compiled a million times? Of course not. > (2) What's the best Ruby way to do a sum from 1 to 1_000_000 Same as in other languages: http://en.wikipedia.org/wiki/Arithmetic_series > (3) Is there a difference in speed between IRB.exe and ruby.exe in > executing the above code? Try it out. Benchmark is your friend. > (4) In IRB, whats the best way to time the code, above? irb(main):004:0> require 'benchmark' => true irb(main):005:0> Benchmark.measure { sleep 2 } => # irb(main):006:0> Benchmark.measure { sleep 2 }.to_s => " 0.000000 0.000000 0.000000 ( 2.000000)\n" irb(main):007:0> Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/