memory - luajit copy table is slow -


within larger lua-script, have copy several tables dt:

for i=1,dt:nrow()     local r = {}     j=1,dt:ncol()         r[j] = dt[i][j]     end          rslt:append(r) end 

the tables 50,000 lines x 25 cols, containing doubles. luajit takes 10 times long "standard" lua. on other calculations/operations before, luajit faster (1.5 3 times).

as silly may sound, try pre-allocating r table 25 values:

local r = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} 

unfortunately lua api doesn't allow pre-allocation of tables, way avoid re-allocations caused array assignment in inner loop. tests show noticeable improvement, not close 10x (although don't use methods, results may vary).


Comments

Popular posts from this blog

how to do line continuation in perl debugger for entering raw multi-line text (EOT)? -

javascript - Create websocket without connecting -

sharepoint - Accessing files across a shared directory using a Windows service -