3 Replies Latest reply on Oct 18, 2007 5:44 PM by kglad

    Is this normal?

    Xx)MaveriK[X]
      Using AS3.

      If I do a class to handle Complex numbers, like

      class Complex {
      public var a:Number, b:Number;
      public function Complex(a, b) { this.a = a; this.b = b; }
      public function add(w:Complex) { a += w.a; b += w.b; }
      }

      and do a loop summing up 100000 times, it is 10x slower than summing two Number variables directly on the loop:

      var t0:uint, a:Number = 0, b:Number = 0, c:Complex = new Complex(0, 0);

      t0 = getTimer();
      for(i=0; i<1000000; i++) { a += a; b += b; }
      trace( getTimer()-t0 ); // 14

      t0 = getTimer();
      for(i=0; i<1000000; i++) c.add(c);
      trace( getTimer()-t0 ); // 145

      Is there a way to optimize function calls?

      Thanks,
      Ian Liu.