comparison Looping.lua @ 11:b952a5d72c9f >>178

Luaのソースコードを追加。2ch.netからの転載。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Thu, 24 Feb 2011 22:23:25 +0900
parents
children
comparison
equal deleted inserted replaced
10:308cc64c24b9 11:b952a5d72c9f
1 --
2 -- This source code was copied from http://hibari.2ch.net/test/read.cgi/tech/1297491072/414
3 --
4
5 Looping = {}
6 Looping_mt = { __index=Looping }
7
8 function Looping.new()
9 tmp = {}
10 tmp.n0 = 0
11 return setmetatable (tmp, Looping_mt)
12 end
13
14 function Looping:calc(n)
15 n1 = self.n0 + (1 - 2*(n%2))
16 self.n0 = n
17 return n1
18 end
19
20 s = Looping.new()
21 c = 0
22 n = 1
23 t1 = os.time()
24
25 while c<2147483647 do
26 n = s:calc(n)
27 c = c + 1
28 end
29
30 t2 = os.time()
31 -- Luaにマイクロ秒を計測するAPIが無いため精度に劣る。
32 print(n, "Lua\t", t2-t1)