Point.distance()は重い
/**
* Copyright CoremindJP ( http://wonderfl.net/user/CoremindJP )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/h09p
*/
package {
import flash.geom.Point;
import flash.display.Sprite;
import flash.utils.getTimer;
import flash.text.TextField;
public class FlashTest extends Sprite {
public var
_resultValue:Number,
_result1:TextField = new TextField(),
_result2:TextField = new TextField(),
_time:int,
_repeat:uint = 10000,
_pointA:Point = new Point(),
_pointB:Point = new Point();
public function FlashTest(){
_result1.width = 425;
_result2.width = 425;
addChild( _result1 );
addChild( _result2 );
//Point.distance
_time = getTimer();
for (var i:int = 0; i < _repeat; i++)
{
_pointA.x = 500;
_pointA.y = 600;
_pointB.x = 700;
_pointB.y = 800;
_resultValue = Point.distance( _pointA, _pointB );
}
_result1.text = "Point.distance = " + String(getTimer() - _time) + "ms\n" + "\tresult = " + _resultValue;
_result2.y = _result1.textHeight;
//Math.sqrt
_time = getTimer();
var _x:int, _y:int;
for (i = 0; i < _repeat; i++)
{
_pointA.x = 500;
_pointA.y = 600;
_pointB.x = 700;
_pointB.y = 800;
_x = _pointA.x - _pointB.x;
_y = _pointA.y - _pointB.y;
_resultValue = Math.sqrt( _x * _x + _y * _y );
}
_result2.text = "Math.sqrt = " + String(getTimer() - _time) + "ms\n" + "\tresult = " + _resultValue;
}
}
}