I tried it out, and I was wondering - is division better than multiplication? I saw it in a post about optimization, but then I created a test and it seems that multiplication is slower. Can someone please clarify?
[lua]
local n
local v
local w=0
local t
for i=1, 10 do
n=system.getTimer()
for i=1, 100000 do
t=display.contentWidth*0.5 – Multiplication
end
v=system.getTimer()-n
w=w+v – Add to the average
end
print("MULTIPLY: "…w*0.1)
w=0
n=system.getTimer()
for i=1, 10 do
n=system.getTimer()
for i=1, 100000 do
t=display.contentWidth/2 – Division
end
v=system.getTimer()-n – Collect the time taken
w=w+v
end
print("DIVIDE: "…w*0.1)
–Result:
– MULTIPLY: 51.5527
– DIVIDE: 50.361
[/lua]
C
