Skip to main content
bit-horder
Participant
January 13, 2015
Question

Strange AIR performance; == faster than ===

  • January 13, 2015
  • 0 replies
  • 144 views

Hi.

I have been hunting down some strange memory usage in one of our games, and tracked it down to numbers being compared to 0.0 in a loop.

I have concentrated the observations down to a small profile snippet.

Observations:

1) I expected the first two profiles to take the same amount of time as everything is typed. But comparing a Number that is a natural is a LOT faster. (only true on desktop and android).

Why is this, is the jitted versions storing Numbers that are natural (whole numbers) as integers, and thus causing a log of type conversion (and memory allocations)?

2) I have been told (and experienced on iOS) that using the === operator is faster than == when a type coercion is possible, test 1+2 vs. 3+4 shows that this is not always the case on some of the platforms.

Is this normal? have I messed up something when building my air apps? If this is reproducible, can somebody with better knowledge of the internals of the AIR runtime explain when it's better to use === over == (for performance).

private var _unused:Number = 0;
private function profileNumberCompare():void
{

   var t0:int = getTimer();
   _unused += profileEqEqEq(0.1);
   var t1:int = getTimer();
   _unused += profileEqEqEq(1.0);
   var t2:int = getTimer();
   _unused += profileEqEq(0.1);
   var t3:int = getTimer();
   _unused += profileEqEq(1.0);
   var t4:int = getTimer();

   trace(t1 - t0);
   trace(t2 - t1);
   trace(t3 - t2);
   trace(t4 - t3);
}

private function profileEqEqEq(inc:Number):Number

{

   var x:Number = 0.0;
   var z:Number = 0.0;
   for(var i:int = 0; i < 10000000; i++)

  {

   if(x === 0.0) z += 1;
   x += inc;
   }

   return z;
}

private function profileEqEq(inc:Number):Number

{

   var x:Number = 0.0;
   var z:Number = 0.0;
   for(var i:int = 0; i < 10000000; i++)

  {

   if(x == 0.0) z += 1;

   x += inc;
   }

   return z;
}

Results:

Desktop, adl  (E5530 @ 2.4GHz):

1411

171

68

71

ipad4:

52

53

53

55

nexus5:

1230

373

148

146

This topic has been closed for replies.