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

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -