Matrix初期化速度
これはこれはw
/**
* Copyright zahir ( http://wonderfl.net/user/zahir )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/as9i
*/
// forked from zahir's Matrix3D初期化速度
package {
import flash.geom.Matrix;
import flash.events.MouseEvent;
import flash.geom.Matrix3D;
import flash.text.TextField;
import flash.display.Sprite;
import flash.utils.getTimer;
public class FlashTest extends Sprite {
private var t:TextField;
public function FlashTest() {
// write as3 code here..
t= new TextField();
addChild(t).width = t.height = 465;
addEventListener( MouseEvent.CLICK, onClick );
ex();
}
private function onClick( e:MouseEvent ):void
{
ex();
}
private function ex():void
{
var m:Matrix;
var _m:Matrix = new Matrix();
var i:int = 0;
var len:int = 1000000;
var time1:int;
var time2:int;
var recode:Array = [];
var count:int = 0;
t.text = "各 " + len + " 回ループ\n\n";
time1 = getTimer();
for( i = 0; i<len; i++ )
{
m = new Matrix();
}
time2 = getTimer() - time1;
recode[count++] = new TimeData( "new", time2, m + "" );
time1 = getTimer();
for( i = 0; i<len; i++ )
{
m = _m.clone();
}
time2 = getTimer() - time1;
recode[count++] = new TimeData( "clone", time2, m + "" );
time1 = getTimer();
for( i = 0; i<len; i++ )
{
m.identity();
}
time2 = getTimer() - time1;
recode[count++] = new TimeData( "identity", time2, m + "" );
time1 = getTimer();
for( i = 0; i<len; i++ )
{
m.a = m.d = 1;
m.b = m.c = m.tx = m.ty = 0;
}
time2 = getTimer() - time1;
recode[count++] = new TimeData( "manual", time2 , m + "");
time1 = getTimer();
for( i = 0; i<len; i++ )
{
m.a = 1;
m.d = 1;
m.b = 0;
m.c = 0;
m.tx = 0;
m.ty = 0;
}
time2 = getTimer() - time1;
recode[count++] = new TimeData( "manual_2", time2 , m + "");
recode.sortOn( "time", Array.NUMERIC );
var max:int = (recode[ recode.length - 1 ] as TimeData).time;
for( i = 0, len = recode.length; i<len; i++)
{
var data:TimeData = recode[i] as TimeData;
var n:int = max / data.time * 100;
t.appendText( data.title + " :: " + data.time + " ms\n\t\t最低速に比べて約 " + n + " %高速 \n");
if(data.ms == "") t.appendText("\n");
else t.appendText( "\t\t" + data.ms + "\n\n");
}
t.appendText("clickで再計算");
}
}
}
import flash.geom.Matrix3D;
class TimeData
{
public var title:String;
public var time:int;
public var ms:String;
public function TimeData( title:String = "", time:int = 0 , ms:String = "")
{
this.title = title;
this.time = time;
this.ms = ms;
}
}