Subscribed unsubscribe Subscribe Subscribe

TI-Nspire & Lua / スクリプティングのヒント / テーブルの最適化 / テーブルのサイズを決めておく

Reference: http://adriweb.free.fr/t3/2014/Advanced_TI-Nspire_Lua_Programming.pptx, p.5
“ Help Lua know more about the tables you're going to use! ”

timeStart = timer.getMilliSecCounter()
for i = 1, 1000000 do
   local a = {}
   a[1] = 1; a[2] = 2; a[3] = 3; a[4] = 4; a[5] = 5
end
print("takes "..timer.getMilliSecCounter() - timeStart.." msec")

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

timeStart = timer.getMilliSecCounter()
for i = 1, 1000000 do
   local a = {true, true, true, true, true}
   a[1] = 1; a[2] = 2; a[3] = 3; a[4] = 4; a[5] = 5
end
print("takes "..timer.getMilliSecCounter() - timeStart.." msec")

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

timeStart = timer.getMilliSecCounter()
for i = 1, 1000000 do
   local a = {nil, nil, nil, nil, nil}
   a[1] = 1; a[2] = 2; a[3] = 3; a[4] = 4; a[5] = 5
end
print("takes "..timer.getMilliSecCounter() - timeStart.." msec")

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

Remove all ads