lua - Should I use ipairs or a for loop -
lua - Should I use ipairs or a for loop -
i have read utilize of ipairs slow compared loop, should alter programming habit? i'll using lua 5.2 1 day, 5.1.
my arrays approximately 1000 items @ most.
local mytbl = { 'a','b','c','e'} i,v in ipairs(mytbl) print(i,v) end i=1,#mytbl print(i,mytbl[i]) end
http://springrts.com/wiki/lua_performance#test_9:_for-loops
pairs: 3.078 (217%) ipairs: 3.344 (236%) i=1,x do: 1.422 (100%) i=1,#atable 1.422 (100%) i=1,atable_length do: 1.562 (110%)
note, however, using numerical for
loop works if you're iterating on tables sequential numeric indices - if you're using hash keys tables, or sparse tables, you'll need utilize form of pairs()
.
lua
Comments
Post a Comment