Mercurial > op > Looping
changeset 8:30da8c1da4d4 >>178
SmalltalkやScalar版のベンチマークを追加。
author | "uncorrelated zombie" <uncorrelated@yahoo.co.jp> |
---|---|
date | Fri, 18 Feb 2011 19:58:26 +0900 |
parents | d788c88f41bd (diff) 69b8c75e9c24 (current diff) |
children | 30b521e712f5 |
files | Looping.rb |
diffstat | 1 files changed, 20 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- 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