From: Aldric Giacomoni Date: 2009-11-26T01:29:47+09:00 Subject: Re: Ruby internals & other questions Ralph Shnelvar wrote: > > y=0 > 1_000_000.times {|x| y+=x} y = (1..1_000_000).inject { |a, b| a + b } More idiomatic, though maybe yours is easier to read at first. If you're not sure what it does, read the rdoc, then ask us questions (rdocs aren't -always- crystal clear). To compare which one is faster, a google search with the keywords : "ruby, benchmark, bmbm" will help. To time the code, the simplest method (though not the most elegant) is to do this: #beginning of code t0 = Time.now #all of code puts "This took #{Time.now - t0} seconds." -- Posted via http://www.ruby-forum.com/.