import flash.utils.getTimer;import flash.geom.Point;var time:Number;var point1:Point=new Point(100,100);var point2:Point=new Point(200,200);var dist:Number;var dx:Number;var dy:Number;function runPythagorean():void{ time = getTimer(); for (var i:int = 0; i < 10000000; i++) { dx = point2.x-point1.x; dy = point2.y-point1.y; dist = Math.sqrt(dx*dx + dy*dy); } trace("runPythagorean(): ", (getTimer()-time));}function runDistance():void{ time = getTimer(); for (var i:int = 0; i < 10000000; i++) { dist = Point.distance(point1,point2); } trace("runDistance(): ", (getTimer()-time));}runPythagorean();runDistance();
//---------------------------------------------------------------------------------------function sqrt(w:Number):Number{// Fast Math sqrt function from // http://osflash.org/as3_speed_optimizations#as3_speed_tests var thresh : Number = 0.002; var b:Number = w * 0.25 var a:Number; var c:Number; if (w == 0) return 0; do { c = w / b; b = (b + c) * 0.5; a = b - c; if (a < 0) a = -a; } while (a > thresh); return b;} //---------------------------------------------------------------------------------------function fsqrt(w:Number):Number{// SUPA fast but not very accurate sqrt// Fast Math sqrt function from // http://osflash.org/as3_speed_optimizations#as3_speed_tests var thresh : Number = 2; //1 var b:Number = w * 0.25 var a:Number; var c:Number; do { c = w / b; b = (b + c) * 0.5; a = b - c; if (a < 0) a = -a; } while (a > thresh); return b;}
Powered by: newtelligence dasBlog 1.9.6264.0
Disclaimer The opinions expressed herein are our personal opinions and do not represent our customer's view in anyway.
© Copyright 2008, gaming your way
E-mail