From: Marnen Laibow-Koser Date: 2009-11-26T01:24:46+09:00 Subject: Re: Ruby internals & other questions Ralph Shnelvar wrote: > Is there a document or website that describes how Ruby works? Well, every interpreter could be implemented a bit differently. There *is* a spec, although I don't know a URL offhand. > > For instance ... > > > > y=0 > 1_000_000.times {|x| y+=x} > > > > (1) Does the block get compiled a million times? Certainly not! The block is an object, and is passed as an argument to the times function. > > (2) What's the best Ruby way to do a sum from 1 to 1_000_000 Gauss's method: def triangular(n) (n + 1) * n / 2 end > > (3) Is there a difference in speed between IRB.exe and ruby.exe in > executing the above code? .exe? What are you, one of those weird Windows users? :) I don't see why there would be a difference -- it's the same interpreter. But why not test it? > > (4) In IRB, whats the best way to time the code, above? I think there's a benchmark library or something like that. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org -- Posted via http://www.ruby-forum.com/.