Mercurial > op > Looping
changeset 11:b952a5d72c9f >>178
Luaのソースコードを追加。2ch.netからの転載。
author | "uncorrelated zombie" <uncorrelated@yahoo.co.jp> |
---|---|
date | Thu, 24 Feb 2011 22:23:25 +0900 |
parents | 308cc64c24b9 |
children | dab1e83799e4 |
files | Looping.lua |
diffstat | 1 files changed, 32 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Looping.lua Thu Feb 24 22:23:25 2011 +0900 @@ -0,0 +1,32 @@ +-- +-- 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)