msec > dynamic, object, array
オブジェクトの生成速度。
早い
宣言済みの型
{}
[]
new Event()
new Array()
new Dictionary()
遅い
/**
* Copyright 110100110101101 ( http://wonderfl.net/user/110100110101101 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/7rNP
*/
// forked from 1110101100101001's forked from: msec : dynamic, object, array
// forked from 1110101100101001's msec : dynamic, object, array
package {
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
addChild( new Test() );
}
}
}
class Task{
public var a:String = "";
public var b:String = "";
public var c:Array;
public var t:Number = 0;
public function Task(){
}
}
import flash.utils.Dictionary;
class Test extends Sprite{
public function Test(){
var note:Note = new Note( this );
var item:ItemA = new ItemA();
var i:int;
var iMax:int = 1000000
note.text = "";
note.start();
for( i=0; i<iMax; ++i ){
}
note.end( " msec : \n");
note.start();
for( i=0; i<iMax; ++i ){
item.c = new Task()
}
note.end( " msec : item.c = new Task() \n");
note.start();
for( i=0; i<iMax; ++i ){
item.c = []
}
note.end( " msec : item.c = [] \n");
note.start();
for( i=0; i<iMax; ++i ){
item.c = {}
}
note.end( " msec : item.c = {} \n");
note.start();
for( i=0; i<iMax; ++i ){
item.c = new Array();
}
note.end( " msec : item.c = new Array(); \n");
note.start();
for( i=0; i<iMax; ++i ){
item.c = new Dictionary();
}
note.end( " msec : item.c = new Dictionary(); \n");
note.start();
for( i=0; i<iMax; ++i ){
item.c = new Event("a");
}
note.end( " msec : item.c = new Event(a); \n");
note.start();
for( i=0; i<iMax; ++i ){
item.c = new Fact();
}
note.end( " msec : item.c = new Fact(); \n");
note.start();
for( i=0; i<iMax; ++i ){
item.hasOwnProperty('c') ? item.c = 1 : null;
}
note.end( " msec : item.hasOwnProperty('c') ? item.c = 1 : null; \n");
note.start();
for( i=0; i<iMax; ++i ){
item.a = 1;
}
note.end( " msec : item.a = 1; \n");
note.start();
for( i=0; i<iMax; ++i ){
item.b = 1;
}
note.end( " msec : item.b = 1; \n");
note.start();
for( i=0; i<iMax; ++i ){
item.c = 1;
}
note.end( " msec : item.c = 1; \n");
item.c = function():void{};
note.start();
for( i=0; i<iMax; ++i ){
item.c();
}
note.end( " msec : item.c(); \n");
note.start();
for( i=0; i<iMax; ++i ){
item.object["a"] = 1;
}
note.end( " msec : item.object['a'] = 1; \n");
note.start();
for( i=0; i<iMax; ++i ){
item.object[0] = 1;
}
note.end( " msec : item.object[0] = 1; \n");
note.start();
for( i=0; i<iMax; ++i ){
item.array[0] = 1;
}
note.end( " msec : item.array[0] = 1; \n");
note.start();
note.end("------------------------ \n");
note.start();
for( i=0; i<iMax; ++i ){
if( item.a ){};
}
note.end( " msec : \n");
note.start();
for( i=0; i<iMax; ++i ){
if( item.b ){};
}
note.end( " msec : \n");
note.start();
for( i=0; i<iMax; ++i ){
if( item.object["a"] ){};
}
note.end( " msec : if( item.object['a'] ){} \n");
note.start();
for( i=0; i<iMax; ++i ){
if( item.object[0] ){};
}
note.end( " msec : if( item.object[0] ){} \n");
note.start();
for( i=0; i<iMax; ++i ){
if( item.array[0] ){};
}
note.end( " msec : if( item.array[0] ){} \n");
note.start();
note.end("------------------------ \n");
note.start();
for( i=0; i<iMax; ++i ){
item.handler("a");
}
note.end( " msec : item.handler('a') \n");
note.start();
for( i=0; i<iMax; ++i ){
item.handler([]);
}
note.end( " msec : item.handler([]) \n");
note.start();
for( i=0; i<iMax; ++i ){
item.handler([1,2]);
}
note.end( " msec : item.handler([1,2]) \n");
note.start();
for( i=0; i<iMax; ++i ){
item.handler([1,2,3,4,5,""]);
}
note.end( " msec : item.handler([1,2,3,4,5]) \n");
note.start();
for( i=0; i<iMax; ++i ){
item.handler({});
}
note.end( " msec : item.handler({}) \n");
note.start();
for( i=0; i<iMax; ++i ){
item.handler({a:1,b:2});
}
note.end( " msec : item.handler({a:1,b:2}) \n");
var message:Object = {a:1}
note.start();
for( i=0; i<iMax; ++i ){
item.handler(message);
}
note.end( " msec : item.handler(message) \n");
note.start();
note.end("------------------------ \n");
note.start();
for( i=0; i<iMax; ++i ){
item.argsHandler(1,2,3,4,5,6,7);
}
note.end( " msec : item.argsHandler(1,2,3,4,5,6,7) \n");
note.start();
for( i=0; i<iMax; ++i ){
item.argsClassCheckHandler(1,2,3,4,5,6,7);
}
note.end( " msec : item.argsClassCheckHandler(1,2,3,4,5,6,7) \n");
note.start();
note.end("------------------------ \n");
note.start();
for( i=0; i<iMax; ++i ){
item.argsHandler.apply(null);
}
note.end( " msec : item.argsHandler.apply(null) \n");
var list:Array = []
note.start();
for( i=0; i<iMax; ++i ){
item.argsHandler.apply(null, list);
}
note.end( " msec : item.argsHandler.apply(null, list) \n");
note.start();
for( i=0; i<iMax; ++i ){
var fact:Fact = new Fact();
fact.time = 0;
fact.time = 0;
fact.time = 0;
fact.time = 0;
fact.time = 0;
item.handler(fact);
}
note.end( " msec : item.handler(new Fact());\n");
note.start();
for( i=0; i<iMax; ++i ){
var fact:Fact = new Fact();
fact.time = 0;
fact.time = 0;
fact.time = 0;
fact.time = 0;
fact.time = 0;
item.handler(fact);
}
note.end( " msec : item.factHandler(new Fact());\n");
note.start();
for( i=0; i<iMax; ++i ){
var fact:Fact = new Fact();
fact.time = 0;
fact.time = 0;
fact.time = 0;
fact.time = 0;
fact.time = 0;
item.argsHandler(fact);
}
note.end( " msec : item.argsHandler(new Fact());\n");
note.start();
for( i=0; i<iMax; ++i ){
item.handler(new Event("a"));
}
note.end( " msec : item.handler(new Event());\n");
note.start();
for( i=0; i<iMax; ++i ){
item.eventHandler(new Event("a"));
}
note.end( " msec : item.eventHandler(new Event());\n");
}
}
class Fact{
public var time:Number = 0;
public function Fact(){
}
}
dynamic class ItemA{
public var a:int = 0;
public var c:*;
public var object:Object = new Object();
public var array:Array = [];
public function handler(data:*):void{
}
public function eventHandler(event:Event):void{
}
public function factHandler(fact:Fact):void{
}
public function argsHandler(...args):void{
}
public function argsClassCheckHandler(...args):void{
if(args[0] is uint){
}
}
}
/////////////////////////////////////////////////////////////////////
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextFormat;
import flash.text.TextField;
import flash.utils.getTimer;
/**
表示だけなら1行で書ける形の着想元
! MinimalComps の com.bit101.components.Component
https://github.com/minimalcomps/minimalcomps/blob/master/src/com/bit101/components/Component.as
*/
class Note extends Sprite {
public function Note( parent:Sprite=null, text:String=" ", x:Number=0,y:Number=0,widthX:Number=200,widthY:Number=100 ){
shape = new Shape();
bitmap = new Bitmap( new BitmapData( 1,1, true, 0x00000000 ) );
textFormat = new TextFormat()
textFormat.leftMargin = 0
textFormat.rightMargin = 0
textFormat.align = "left"
textFormat.font = "_等幅" //EXAMPLE "_等幅" "_ゴシック" "_明朝 " "_typewriter" "_serif" "_sans"
textFormat.size = 10
textField = new TextField()
textField.background = false;
textField.backgroundColor = 0xFFFFFF;
textField.border = false;
textField.borderColor = 0x000000;
textField.textColor = 0x000000;
textField.autoSize = "left";
textField.selectable = false;
textField.text = text;
textField.defaultTextFormat = textFormat;
this.text = text;
this.x = x;
this.y = y;
textField.width = widthX;
textField.height = widthY;
displayEnable( parent );
addEventListener( Event.ENTER_FRAME, onEnterFrame );
}
private function onEnterFrame( event:Event ):void {
textField.text = text;
}
public function displayEnable( parent:Sprite ):void{
if( parent ){
parent.addChild( this );
addChild( textField );
addChild( shape );
addChild( bitmap );
}
}
public function displayDisenable():void{
if( parent ){
parent.removeChild( this );
removeChild( textField );
removeChild( shape );
removeChild( bitmap );
}
}
public function start( startText:String = "" ):void{
startTime = getTimer();
text = text + startText;
}
public function end( endText:String = "" ):void{
endTime = getTimer();
elapsedTime = endTime - startTime;
text = text + elapsedTime.toString() + endText;
}
public function toBitmapData():BitmapData{
var result:BitmapData
result = new BitmapData( this.width, this.height, true, 0x00000000 );
result.draw( this );
return result;
}
public var elapsedTime:Number = 0;
public var endText:String = "";
public var endTime:Number = 0;
public var iMax:uint = 1000000;
public var startText:String = "";
public var startTime:Number = 0;
public var text:String
public var textFormat:TextFormat
public var textField:TextField
public var bitmap:Bitmap;
public var shape:Shape
}