notice: Flash editor updated! Join the development! Thanks to MiniBuilder


embed

FORKED

最適化Tips 配列の要素にアクセスする時にASで型変換 forked from: 最適化Tips 配列の要素にアクセスする時にASで型変換 [diff(25)]

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" applicationComplete="appCompleteHandler(event)">
  3.     <mx:Script>
  4.     <![CDATA[
  5.     import flash.events.MouseEvent;
  6.     import mx.events.FlexEvent;
  7.     import mx.controls.Alert;
  8.     import flash.system.Capabilities;
  9.     import flash.utils.getTimer;
  10.     import flash.geom.Point;
  11.     
  12.     private var loopCount:int = 1000000;
  13.     private var ary:Array;
  14.     public function appCompleteHandler(event:FlexEvent):void{
  15.         if(Capabilities.isDebugger){
  16.             var msg:String = "デバッグ版のプレーヤを使用しています。正しいベンチマークの結果を得るにはリリース版を使用することをお勧めします。";
  17.             Alert.show(msg, "インフォメーション");
  18.         }
  19.         console.text += "OS : " + Capabilities.os + "\n";
  20.         console.text += "Vesion : " + Capabilities.version + "\n";
  21.         console.text += "Type : " + Capabilities.playerType + "\n";
  22.         Capabilities.isDebugger ? console.text += "Debug version\n" : null;
  23.     }
  24.     public function clickHandler(event:MouseEvent):void{
  25.         startBenchmark();
  26.     }
  27.     public function clear(event:MouseEvent):void {
  28.         console.text = "";
  29.     }
  30.     public function startBenchmark():void{
  31.         var time:int;
  32.         var dt:int;
  33.         var i:int;
  34.         var p:Point;
  35.         ary = new Array();
  36.         ary.push(new Point());
  37.         
  38.         i = 0;
  39.         time = getTimer();
  40.         while(i < loopCount){
  41.             (p = Point(ary[0])).x = 0;
  42.             p.y = 0;
  43.             i++;
  44.         }
  45.         dt = getTimer() - time;
  46.         console.text += "キャストする場合" + dt + "ms\n"
  47.         i = 0;
  48.         time = getTimer();
  49.         while(i < loopCount){
  50.             (p = ary[0as Point).x = 0;
  51.             p.y = 0;
  52.             i++;
  53.         }
  54.         dt = getTimer() - time;
  55.         console.text += "ASによるキャスト" + dt + "ms\n"
  56.         i = 0;
  57.         time = getTimer();
  58.         while(i < loopCount){
  59.             (p = ary[0]).x = 0;//微妙にasの方が早い?
  60.             p.y = 0;
  61.             i++;
  62.         }
  63.         dt = getTimer() - time;
  64.         console.text += "キャストしない場合" + dt + "ms\n"
  65.                 i = 0;
  66.         time = getTimer();
  67.         while(i < loopCount){
  68.             p = ary[0];
  69.                         p.x = 0;
  70.             p.y = 0;
  71.             i++;
  72.         }
  73.         dt = getTimer() - time;
  74.         console.text += "あまり.で繋げない場合" + dt + "ms\n"
  75. i = 0;
  76.         time = getTimer();
  77.         while(i < loopCount){
  78.             with(ary[0]){
  79.                             x = 0;
  80.             y = 0;
  81.                             }
  82.             i++;
  83.         }
  84.         dt = getTimer() - time;
  85.         console.text += "あかん" + dt + "ms\n"
  86.         console.text += "\n"
  87.     }
  88.     ]]>
  89.     </mx:Script>
  90.     <mx:VBox width="100%" height="100%">
  91.         <mx:TextArea id="console" width="100%" height="100%"></mx:TextArea>
  92.         <mx:HBox width="100%">
  93.             <mx:Button label="Start" click="clickHandler(event)" />
  94.             <mx:Button label="Clear" click="clear(event)" />
  95.         </mx:HBox>
  96.     </mx:VBox>
  97. </mx:Application>
noswf
Get Adobe Flash Player