Recently, I tried to solve a performance problem, and found function calls cost more than 10 floating multiplies!
Here is the sample code :
– empty function
local function test()
return 0
end
local x=77.1
local y=11.1
local t0=system.getTimer()
for i=1,100000 do
local v = y*x
end
local t1=system.getTimer()
for i=1,100000 do
local v = test()
end
local t2=system.getTimer()
print(string.format(“t1-t0 = %.2f, t2-t1 = %.2f”, t1-t0, t2-t1))
With iPhone4, We got : t1-t0 = 45.17, t2-t1 = 630.60
The cost of one function call is more than 13 float multiplies !
So, I have to reduce the function call in enterFrame() and avoid call functions in loops.
With that, I can’t write a more structured code with functions.
Or did I missed something ?