Subscribed unsubscribe Subscribe Subscribe

TI-Nspire & Lua / スクリプティングのヒント / テーブルの末尾に要素を追加するときは table.insert() を使わない

Nspired Lua スクリプティングのヒント

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

local num = 3000000


-- 1
local list = {}
local timeStart = timer.getMilliSecCounter()
for i = 1, num do
   table.insert(list, i)
end
local timeStop = timer.getMilliSecCounter()
print("1: takes "..timeStop - timeStart.." msec")


list, timeStart, timeStop = nil, nil, nil


-- 2
local list = {}
local timeStart = timer.getMilliSecCounter()
for i = 1, num do
   list[#list + 1] = i
end
local timeStop = timer.getMilliSecCounter()
print("2: takes "..timeStop - timeStart.." msec")

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

Remove all ads