I have a piece of code running into an loop, with a division by 100, which is reducing a little my fps count.
In majority of cases, is a int/uint type being divided by 100, resulting in a simple Number.
I just want to know any way to optimize that.
EDIT: Little benchmark with the @scriptocalypse suggestion - multiplying for 0.01:
import flash.utils.getTimer;
for(var k:Number = 20; k > 0; k--)
{
var a:int = getTimer();
var o:Number = 100;
var p:Number;
for(var i:Number = 100000000; i > 0; i--)
{
p = o * 0.01; // took 423~510 <--------------
//p = o / 100; // took 713~768 <--------------
}
var b:int = getTimer();
trace( b - a);
}
I suspect that it's not the division that's causing the bulk of your issues, as even slow math operations should be relatively fast compared to other operations.
While this:
x * 0.01;
should theoretically be faster than
x / 100;
I still suspect that it won't make much difference. What else are you doing in your loop?
Almost certainly, the right answer is don't. Programmers should write code that is clear to read, compilers should optimize.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With