zoukankan      html  css  js  c++  java
  • var读写和function读写,get/set读写效率比较

    var读写和function读写,get/set读写效率比较

    var 比 function快4倍左右,

    get/set和function差不多

    95
    var 读: 567
    var 写: 563
    [SWF] D:\flexProject\testSpeed\bin-debug\testSpeed.swf - 2,091 bytes after decompression
    function 读: 1860
    function 写: 2117
    get/set 读: 1927
    get/set 写: 2119

    //测试代码

    package {
     import flash.display.Sprite;
     import flash.utils.getTimer;

     public class testSpeed extends Sprite
     {
      public function testSpeed()
      {
       var aone:speedTest=new speedTest()  ;
       var max:int=5000000;//50000000
       var old:int=getTimer();
       for (var i:int = 0; i < max; i+=1) {
       
       }
       
       //var forTime:int=getTimer()-old;
       old=getTimer();
       
       //trace(forTime);
       trace(old);
       
       //
       var t:int=0;
       for (i = 0; i < max; i+=1) {
        t=aone.testVar;
       }
       trace("var 读:",getTimer() - old);// - forTime);
       
       old=getTimer();
       for (i = 0; i < max; i+=1) {
        aone.testVar=t;
       }
       trace("var 写:",getTimer() - old);// - forTime);
       //
       old=getTimer();
       //
       for (i = 0; i < max; i+=1) {
        t=aone.testFunctionGet();
       }
       trace("function 读:",getTimer() - old);// - forTime);
       old=getTimer();
       for (i = 0; i < max; i+=1) {
        aone.testFunctionSet(t);
       }
       trace("function 写:",getTimer() - old);// - forTime);
       
       //
       old=getTimer();
       //
       for (i = 0; i < max; i+=1) {
        t=aone.testGet;
       }
       trace("get/set 读:",getTimer() - old);// - forTime);
       old=getTimer();
       for (i = 0; i < max; i+=1) {
        aone.testSet=t;
       }
       trace("get/set 写:",getTimer() - old);// - forTime);
      }
     }
    }

    //

    package{
     public class speedTest{
      public function speedTest(){}  
      public var testVar:int = 0;
      private var _function:int = 0;
      private var _getset:int = 0;
      public function testFunctionGet():int{
       return this._function;
      }
      public function testFunctionSet(i:int):void{
       this._function = i;
      }
      public function set testSet(i:int):void{
       this._getset = i;
      }
      public function get testGet():int{
       return this._getset;
      }
      
     }
    }

  • 相关阅读:
    BZOJ 2006: [NOI2010]超级钢琴 [ST表+堆 | 主席树]
    CF 741D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths [dsu on tree 类似点分治]
    CF 716E. Digit Tree [点分治]
    CF 291E. Tree-String Problem [dfs kmp trie图优化]
    CF 208E. Blood Cousins [dsu on tree 倍增]
    CF 246E. Blood Cousins Return [dsu on tree STL]
    CF 570D. Tree Requests [dsu on tree]
    [dsu on tree]【学习笔记】
    测试markdown
    BZOJ 1969: [Ahoi2005]LANE 航线规划 [树链剖分 时间倒流]
  • 原文地址:https://www.cnblogs.com/jiahuafu/p/1727880.html
Copyright © 2011-2022 走看看