Math Operator Speed

According to the Corona Programming Guide at http://bit.ly/hwL7nl, multiplication yields faster results than division.
Therefore, would…

fog.x \> 480 + fog.width / 2  

… be better written as…

fog.x \> 480 + fog.width \*0.5  

Thoughts? [import]uid: 12397 topic_id: 6872 reply_id: 306872[/import]

yes, it specifically states that example!!

Math: fast vs slow
Multiplication x*0.5 is faster than division x/2.

but also read this:
http://developer.anscamobile.com/forum/2010/11/13/performance-tip-setting-isvisiblefalse-slow-reading-display-object-xy-slow

if fog.width is constant it might be faster caching it as a local value, and reusing it in calculations

ie [lua]local fogHalfWidth = fog.width * 0.5[/lua]

of course this only probably really matters if you’re doing that for lots of objects like in my example [import]uid: 6645 topic_id: 6872 reply_id: 23981[/import]

Great idea THX!

I do use many of these and they’re all constant widths… plus they sit in two different enterFrame functions called from two different buttons.

Question: Since they’re in an enterFrame, are they being recalculated each frame?

Question: Would I use your cached calculation like so…

fog.x \> 480 + fogHalfWidth  

Question: Should the local pre-calculation variable go inside of the functions containing the calculations?

Sorry if these are dumb questions… as the name says, I’m StillLearning.

Thanks again.

[import]uid: 12397 topic_id: 6872 reply_id: 23993[/import]

if fog width is constant throughout your app then you could just put the definition right at the top of your file. (if you know the value before you’ve even loaded the fog for instance). again this is quite extreme optimisation though…does you game actually need it? is it dropping framerate?

[import]uid: 6645 topic_id: 6872 reply_id: 24041[/import]