Mercurial > op > Looping
view Looping.rb @ 6:5e09f7cf87f5
Perl版のソースコードを追加。
author | "uncorrelated zombie" <uncorrelated@yahoo.co.jp> |
---|---|
date | Thu, 17 Feb 2011 15:32:22 +0900 |
parents | 861b93741d60 |
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"