Mercurial > op > Looping
diff 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 diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Looping.rb Thu Feb 17 11:32:17 2011 +0900 @@ -0,0 +1,22 @@ +#!/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" +