型指定配列と型無指定配列でパフォーマンスがあまり変わらない気が
左上に計算時間を
型指定なし/型指定あり
で表示
/**
* Copyright aont ( http://wonderfl.net/user/aont )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/xvye
*/
package {
/*
左上に計算時間を
型指定なし/型指定あり
で表示
*/
import flash.display.Sprite;
import flash.utils.getTimer;
import flash.text.TextField;
public class FlashTest extends Sprite {
private static var N:int = 1 << 17;
public function FlashTest() {
var tf:TextField = new TextField();
this.addChild(tf);
var time1:int =0;
var time2:int =0;
CastEachTime();
time1 = CastEachTime();
time2 = NumberArray();
tf.text = time1.toString()+"/"+time2.toString();
}
private static function CastEachTime():int
{
var start:int;
var end:int;
var i:int;
var array:Array = new Array(N);
var S:Number=0;
start = getTimer();
for(i=0;i<N;++i)
{
array[i] = Math.exp(i);
}
for(i=0;i<N;++i)
{
S += array[i];
}
end = getTimer();
return end-start;
}
private static function NumberArray():int
{
var start:int;
var end:int;
var i:int;
[ArrayElementType("Number")]
var array:Array = new Array(N);
var S:Number=0;
start = getTimer();
for(i=0;i<N;++i)
{
array[i] = Math.exp(i);
}
for(i=0;i<N;++i)
{
S += array[i];
}
end = getTimer();
return end-start;
}
}
}