local test = {} for i = 10, 10000 do test[ i ] = {} end local t1 = os.clock( ) for i = 1, 100000 do test[ 1000 ].mValue = 100 end local t2 = os.clock( ) - t1 Misc.Trace( "cost - " .. t2 ) t1 = os.clock( ) local d = test[ 1000 ] for i = 1, 100000 do d.mValue = 100 end t2 = os.clock( ) - t1 Misc.Trace( "cost - " .. t2 )
這兩個效率有很大差異
上面這個消耗 3毫秒 下面這個消耗 1毫秒
如今項目裏面有不少不必重複索引
能夠先用一個本地變量記錄下來,不用每次都重複索引
這樣能夠提高效率spa