Mercurial > op > Looping
view Looping.rb @ 5:861b93741d60
id:sumim氏のSmalltalk版とRuby版のコードを追加。
author | "uncorrelated zombie" <uncorrelated@yahoo.co.jp> |
---|---|
date | Thu, 17 Feb 2011 11:32:17 +0900 |
parents | |
children | 30da8c1da4d4 |
line wrap: on
line source
#!/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 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"