Allright, I'm willing to admit when I'm wrong and it seems I am wrong about the bitshifting. I took a closer look at the test on businnessintelligence's website and while I don't see anything wrong with it, I ran my own as suggested and the results were interesting if not exaclty staggering.
you can copy that exactly onto any timeline object and run it to see what I am talking about. Basically, at 1 million iterations, the trace results round to 4 and 8 milliseconds each, seems pretty compellingly like a huge speed up right? Well its a bit more clear when run at 50 million iterations... what makes me happy about the validity of these results is the deterministic quality. I can run this test over and over( just click ) and the results are only off by maybe a millisecond or two. Not bad for 50 million iterations.
>>1
208
/2
393
Still, while it is a 89% increase in speed it is only actually worth anything over a rediculously large number of iterations.
Plus, I'd like to point out that this function isn't actually doing anything. In reality its just assigning the value 5 to the count variable and a smart optimizer would just replace that with count = 5;
Wait, that gives me an idea. I'll just check that for results and while I'm at it, I'm going to make the function actually do some work.
New Code.
the results are:
i>>1
211
i*0.5
387
=5
209
If it will make box2d faster... I really don't know. As I said about the broadphase, I'm not sure its worth putting any time into since its likely to be replaced soon.
Code:
stage.addEventListener( MouseEvent.CLICK, click );
function click( e:MouseEvent ):void
{
var time:int = getTimer();
var count:int = 1;
for( var i:int = 0; i < 1000000; ++i )
{
count = 10 >> 1;
}
time = (getTimer() - time);
trace( count );
trace( time );
time = getTimer();
for( var i:int = 0; i < 1000000; ++i )
{
count = 10 / 2;
}
time = (getTimer() - time);
trace( count );
trace( time )
}
function click( e:MouseEvent ):void
{
var time:int = getTimer();
var count:int = 1;
for( var i:int = 0; i < 1000000; ++i )
{
count = 10 >> 1;
}
time = (getTimer() - time);
trace( count );
trace( time );
time = getTimer();
for( var i:int = 0; i < 1000000; ++i )
{
count = 10 / 2;
}
time = (getTimer() - time);
trace( count );
trace( time )
}
you can copy that exactly onto any timeline object and run it to see what I am talking about. Basically, at 1 million iterations, the trace results round to 4 and 8 milliseconds each, seems pretty compellingly like a huge speed up right? Well its a bit more clear when run at 50 million iterations... what makes me happy about the validity of these results is the deterministic quality. I can run this test over and over( just click ) and the results are only off by maybe a millisecond or two. Not bad for 50 million iterations.
>>1
208
/2
393
Still, while it is a 89% increase in speed it is only actually worth anything over a rediculously large number of iterations.
Plus, I'd like to point out that this function isn't actually doing anything. In reality its just assigning the value 5 to the count variable and a smart optimizer would just replace that with count = 5;
Wait, that gives me an idea. I'll just check that for results and while I'm at it, I'm going to make the function actually do some work.
New Code.
Code:
function click( e:MouseEvent ):void
{
var time:int = getTimer();
//var count:int = 1;
for( var i:int = 0; i < 50000000; ++i )
{
var count:int = int(i >> 1);
}
time = (getTimer() - time);
trace( count );
trace( time );
time = getTimer();
for( var i:int = 0; i < 50000000; ++i )
{
var count:int = int(i * 0.5);
}
time = (getTimer() - time);
trace( count );
trace( time )
time = getTimer();
for( var i:int = 0; i < 50000000;++i )
{
var count:int = 5;
}
time = (getTimer() - time);
trace( count );
trace( time )
}
{
var time:int = getTimer();
//var count:int = 1;
for( var i:int = 0; i < 50000000; ++i )
{
var count:int = int(i >> 1);
}
time = (getTimer() - time);
trace( count );
trace( time );
time = getTimer();
for( var i:int = 0; i < 50000000; ++i )
{
var count:int = int(i * 0.5);
}
time = (getTimer() - time);
trace( count );
trace( time )
time = getTimer();
for( var i:int = 0; i < 50000000;++i )
{
var count:int = 5;
}
time = (getTimer() - time);
trace( count );
trace( time )
}
the results are:
i>>1
211
i*0.5
387
=5
209
If it will make box2d faster... I really don't know. As I said about the broadphase, I'm not sure its worth putting any time into since its likely to be replaced soon.