# HG changeset patch # User "uncorrelated zombie" # Date 1298026706 -32400 # Node ID 30da8c1da4d4fb92e7209c4474811024feff145a # Parent d788c88f41bd72d3491be747967738163f4d7323# Parent 69b8c75e9c247ba3cb3b54e54ce3fd50ac206ed9 SmalltalkやScalar版のベンチマークを追加。 diff -r 69b8c75e9c24 -r 30da8c1da4d4 Looping.rb --- a/Looping.rb Fri Feb 18 10:32:06 2011 +0900 +++ b/Looping.rb Fri Feb 18 19:58:26 2011 +0900 @@ -1,22 +1,24 @@ #!/usr/bin/env ruby class Looping - def initialize - @n0 = 0 - end - - def calc(n) - n1 = @n0 + (1 - 2*(n%2)) - @n0 = n - return n1 - end + def initialize() + @n0 = 0 + end + def calc(n) + n1 = @n0 + (1 - 2*(n%2)) + @n0 = n + n1 + end end -l = Looping.new -n = 1 -t1 = Time.now -2147483647.times{ |c| - n = l.calc(n) -} -t2 = Time.now -print "#{n}\nRuby\t#{t2 - t1}\n" - +if __FILE__ == $0 + s = Looping.new + c = 0 + n = 1 + t1 = Time.now + while c<2147483647 + n = s.calc(n) + c+=1 + end + t2 = Time.now + puts "#{n} Ruby\t#{t2-t1}" +end