Matrix初期化の速度実験

by zahir
♥0 | Line 30 | Modified 2009-08-14 00:21:58 | MIT License
play

ActionScript3 source code

/**
 * Copyright zahir ( http://wonderfl.net/user/zahir )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1Y1h
 */

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
	width="465" height="465" applicationComplete="init()">
	<mx:Script>
		<![CDATA[
			private var len:int = 1000000;
			private function init():void{
				play();
			}
			private function play():void{
				var m1:Matrix = new Matrix();
				
				var t1:int = getTimer();
	            for(var i:int=0; i<len; i++){ m1.identity();}
    	        var t2:int = getTimer()-t1;
    	        var str:String = "identity()  :: "  + t2 + " ms\n";
    	        
    	        t1 = getTimer();
    	        for(i=0; i<len; i++){ m1 = new Matrix();}
    	        t2 = getTimer() - t1;
    	        str += "new Matrix()  :: "  + t2 + " ms\n";
    	        
    	        t1 = getTimer();
    	        for(i=0; i<len; i++){ m1.a = m1.d = 1;m1.b = m1.c = m1.tx = m1.ty = 0;}
    	        t2 = getTimer() - t1;
    	        str += "a,b,c,d,tx,ty  :: "  + t2 + " ms\n\n";
    	        
    	        t.text += str;
			}
		]]>
	</mx:Script>
	<mx:Button label="try" click="play();" right="5" top="5" />
	<mx:TextArea id="t" left="5" right="5" bottom="8" top="30"/>
</mx:Application>