Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local SysTime = SysTime
- local print = print
- local t = {}
- for i = 1, 1e3 do
- t[i] = i
- end
- do
- local function b(t)
- local total = 0
- for _, v in ipairs(t) do
- total = total + v
- end
- end
- local nStart = SysTime()
- for i = 1, 1e6 do
- b(t)
- end
- print("ipairs", SysTime() - nStart)
- end
- do
- local function b(t)
- local total = 0
- for i = 1, 1e3 do
- total = total + t[i]
- end
- end
- local nStart = SysTime()
- for i = 1, 1e6 do
- b(t)
- end
- print("for", SysTime() - nStart)
- end
- do
- local function b(t)
- local total = 0
- for i = 1e3, 1, -1 do
- total = total + t[i]
- end
- end
- local nStart = SysTime()
- for i = 1, 1e6 do
- b(t)
- end
- print("reverse for", SysTime() - nStart)
- end
- do
- local function b(t)
- local total = 0
- local i = 0
- ::GOTO::
- i = i + 1
- total = total + t[i]
- if (i ~= 1e3) then
- goto GOTO
- end
- end
- local nStart = SysTime()
- for i = 1, 1e6 do
- b(t)
- end
- print("goto", SysTime() - nStart)
- end
- do
- local function b(t)
- local total = 0
- local i = 1e3
- ::GOTO_REVERSE::
- total = total + t[i]
- i = i - 1
- if (i ~= 0) then
- goto GOTO_REVERSE
- end
- end
- local nStart = SysTime()
- for i = 1, 1e6 do
- b(t)
- end
- print("reverse goto", SysTime() - nStart)
- end
- do
- local function b(t)
- local total = 0
- local i = 0
- while (i ~= 1e3) do
- i = i + 1
- total = total + t[i]
- end
- end
- local nStart = SysTime()
- for i = 1, 1e6 do
- b(t)
- end
- print("while", SysTime() - nStart)
- end
- do
- local function b(t)
- local total = 0
- local i = 1e3
- while (i ~= 0) do
- total = total + t[i]
- i = i - 1
- end
- end
- local nStart = SysTime()
- for i = 1, 1e6 do
- b(t)
- end
- print("reverse while", SysTime() - nStart)
- end
- do
- local function b(t)
- local total = 0
- local i = 0
- repeat
- i = i + 1
- total = total + t[i]
- until (i == 1e3)
- end
- local nStart = SysTime()
- for i = 1, 1e6 do
- b(t)
- end
- print("repeat until", SysTime() - nStart)
- end
- do
- local function b(t)
- local total = 0
- local i = 1e3
- repeat
- total = total + t[i]
- i = i - 1
- until (i == 0)
- end
- local nStart = SysTime()
- for i = 1, 1e6 do
- b(t)
- end
- print("reverse repeat until", SysTime() - nStart)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement