SimpleLoop – haXe

simpleloop-hx.swf

The result of a simple looping haXe programme:

SimpleLoop.hx
   import flash.display.Sprite;
   import flash.Lib;
   import flash.utils.Timer;
   import flash.text.TextField;

   class SimpleLoop extends Sprite
   {
      function new()
      {
         super();
         flash.Lib.current.addChild(this);

         var timer:Float = Lib.getTimer();
         var sum:Int = Run1();
         timer = Lib.getTimer()-timer;

         var display:TextField = new TextField();
         display.x=10;
         display.y=10;
         display.width=190;
         display.text = "HX ... : " + timer + " ms = " + sum;
         addChild(display);

         timer = Lib.getTimer();
         var sum2:Int = Run2();
         timer = Lib.getTimer()-timer;

         var display2:TextField = new TextField();
         display2.x=10;
         display2.y=50;
         display2.width=190;
         display2.text = "HX while : " + timer + " ms = " + sum2;
         addChild(display2);


      }


      function Run1() : Int
      {
         var sum:Int = 0;
         for(j in 0...1000)
         {
            sum = 0;
            for(i in 0...10000)
               sum += i;
         }
         return sum;
      }


      function Run2() : Int
      {
         var sum:Int = 0;
         var j:Int = 0;
         while(j < 1000)
         {
            sum = 0;
            var i:Int = 0;
            while(i<10000)
            {
               sum += i;
               i++;
            }
            j++;
         }
         return sum;
      }



      static function main() : Void
         { new SimpleLoop(); }

    }
   

Leave a Reply

Your email address will not be published. Required fields are marked *