Subscribed unsubscribe Subscribe Subscribe

TI-Nspire & Lua / スクリプティングのヒント / ipairs() は使わない

Reference: http://adriweb.free.fr/t3/2014/Advanced_TI-Nspire_Lua_Programming.pptx, p.8

local list = {}
for i = 1, 5000000 do
   list[i] = i
end


-- 1
timeStart = timer.getMilliSecCounter()
for i = 1, #list do
   local index = i
   local value = list[i]
end
print("1: takes "..timer.getMilliSecCounter() - timeStart.." msec")


-- 2
timeStart = timer.getMilliSecCounter()
for i, v in ipairs(list) do
   local index = i
   local value = v
end
print("2: takes "..timer.getMilliSecCounter() - timeStart.." msec")

f:id:ti-nspire:20170202070535p:plain

Remove all ads