From: "ara.t.howard" Date: 2007-10-27T14:18:47+09:00 Subject: Re: How fast does your Ruby run? On Sep 20, 2007, at 4:49 PM, SpringFlowers AutumnMoon wrote: > How fast does your Ruby run? > > I got 53648 iterations per second running the following program, > on an Intel 3.2 GHz HT, Win XP machine: > > -------- > > C:\> ruby calculate.rb > 55 > > Ruby 1.8.6 patch 0 on i386-mswin32 > It took 18.64 seconds to run. 53648 iterations per second. > > -------- > > n = 1_000_000 > > start_time = Time.now > > for i in 1..n > t = (1..10).inject {|x, y| x + y } > end > > finish_time = Time.now > > p t > > puts > print "Ruby ", RUBY_VERSION, " patch ", RUBY_PATCHLEVEL, " on ", > RUBY_PLATFORM > > puts > print "It took #{finish_time - start_time} seconds to run." > print " #{(n / (finish_time - start_time)).to_i} iterations per > second.\n" cfp:~ > cat a.rb require 'narray' n = 1_000_000 t = nil start_time = Time.now n.times{ t = NArray.int(10).indgen!(1).sum } finish_time = Time.now p t puts print "Ruby ", RUBY_VERSION, " patch ", RUBY_PATCHLEVEL, " on ", RUBY_PLATFORM puts print "It took #{finish_time - start_time} seconds to run." print " #{(n / (finish_time - start_time)).to_i} iterations per second.\n" cfp:~ > ruby a.rb 55 2GHz osx Ruby 1.8.6 patch 0 on i686-darwin8.9.1 It took 2.893815 seconds to run. 345564 iterations per second. a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama