Mercurial > op > Looping
view Looping.lua @ 12:dab1e83799e4 >>178 tip
R版のソースコードを追加。
author | "uncorrelated zombie" <uncorrelated@yahoo.co.jp> |
---|---|
date | Sat, 04 Feb 2012 04:10:01 +0900 |
parents | b952a5d72c9f |
children |
line wrap: on
line source
-- -- This source code was copied from http://hibari.2ch.net/test/read.cgi/tech/1297491072/414 -- Looping = {} Looping_mt = { __index=Looping } function Looping.new() tmp = {} tmp.n0 = 0 return setmetatable (tmp, Looping_mt) end function Looping:calc(n) n1 = self.n0 + (1 - 2*(n%2)) self.n0 = n return n1 end s = Looping.new() c = 0 n = 1 t1 = os.time() while c<2147483647 do n = s:calc(n) c = c + 1 end t2 = os.time() -- Luaにマイクロ秒を計測するAPIが無いため精度に劣る。 print(n, "Lua\t", t2-t1)