new tips
老外的一篇文章(原文地址http://stackoverflow.com/questions/6647677/tips-for-efficient-as3-coding),有这么一段描述:
Use [] and new Object(), instead of, new Array() and {}. It is at best 3 times faster. And is extremely common for the more costly operation to occur in loops.
Generally speaking, the new keyword is just plain expensive.
import flash.utils.getTimer;publicvar _time:Number;publicvar _simpleArrayTime:Number;publicvar buffer:Array;publicfunction testArray():void{
    trace("----------------Array Test--------------");
    _time = getTimer();for(var a:int=0; a <100000; a++)
        buffer =[];
    _simpleArrayTime = getTimer()- _time;
    trace("[] * 100000 :"+_simpleArrayTime.toPrecision(21));
    _time = getTimer();for(var b:int=0; b <100000; b++)
        buffer =newArray();
    _simpleArrayTime = getTimer()- _time;
    trace("new Array() * 100000 :"+_simpleArrayTime.toPrecision(21));
    _time = getTimer();for(var c:int=0; c <100000; c++)
        buffer =[];
    _simpleArrayTime = getTimer()- _time;
    trace("[] * 100000 :"+_simpleArrayTime.toPrecision(21));}publicvar objBuffer:Object;publicfunction testObject():void{
    trace("----------------Object Test--------------");
    _time = getTimer();for(var a:int=0; a <100000; a++)
        objBuffer ={};
    _simpleArrayTime = getTimer()- _time;
    trace("{} * 100000 :"+_simpleArrayTime.toPrecision(21));
    _time = getTimer();for(var b:int=0; b <100000; b++)
        objBuffer =newObject();
    _simpleArrayTime = getTimer()- _time;
    trace("new Object() * 100000 :"+_simpleArrayTime.toPrecision(21));
    _time = getTimer();for(var c:int=0; c <100000; c++)
        objBuffer ={};
    _simpleArrayTime = getTimer()- _time;
    trace("{} * 100000 :"+_simpleArrayTime.toPrecision(21));}publicfunction runTests(event:Event=null):void{
    testArray();
    testObject();
}
----------------Array Test--------------
[] * 100000 :82.0000000000000000000
new Array() * 100000 :152.000000000000000000
[] * 100000 :53.0000000000000000000
----------------Object Test--------------
{} * 100000 :53.0000000000000000000
new Object() * 100000 :36.0000000000000000000
{} * 100000 :53.0000000000000000000
但在我本地的三次测试结果是这样的(WIN7+FB4.6+SDK4.6):
----------------Array Test--------------
[] * 100000 :42.0000000000000000000
new Array() * 100000 :117.000000000000000000
[] * 100000 :43.0000000000000000000
----------------Object Test--------------
[SWF] E:\yueyi\code\workspace\MyDemo\bin-debug\MyDemoTwo.swf - 2,313 bytes after decompression
{} * 100000 :31.0000000000000000000
new Object() * 100000 :30.0000000000000000000
{} * 100000 :30.0000000000000000000
----------------Array Test--------------
[] * 100000 :46.0000000000000000000
new Array() * 100000 :124.000000000000000000
[SWF] E:\yueyi\code\workspace\MyDemo\bin-debug\MyDemoTwo.swf - 2,313 bytes after decompression
[] * 100000 :46.0000000000000000000
----------------Object Test--------------
{} * 100000 :27.0000000000000000000
new Object() * 100000 :29.0000000000000000000
{} * 100000 :28.0000000000000000000
----------------Array Test--------------
[] * 100000 :45.0000000000000000000
new Array() * 100000 :112.000000000000000000
[] * 100000 :43.0000000000000000000
----------------Object Test--------------
[SWF] E:\yueyi\code\workspace\MyDemo\bin-debug\MyDemoTwo.swf - 2,313 bytes after decompression
{} * 100000 :28.0000000000000000000
new Object() * 100000 :28.0000000000000000000
{} * 100000 :30.0000000000000000000
所以说,[]比new Array要快,但{}并不比new Object快!
new tips的更多相关文章
- Mac上MySQL忘记root密码且没有权限的处理办法&workbench的一些tips (转)
		忘记Root密码肿么办 Mac上安装MySQL就不多说了,去mysql的官网上下载最新的mysql包以及workbench,先安装哪个影响都不大.如果你是第一次安装,在mysql安装完成之后,会弹出来 ... 
- 【Tips】史上最全H1B问题合辑——保持H1B身份终级篇
		[Tips]史上最全H1B问题合辑——保持H1B身份终级篇 2015-04-10留学小助手留学小助手 留学小助手 微信号 liuxue_xiaozhushou 功能介绍 提供最真实全面的留学干货,帮您 ... 
- layer.js中layer.tips
		<script src="~/Content/js/layer/layer.js"></script> layer.tips('名称不能为空', '#pro ... 
- HTML 最简单的tips 怎么支持指定DIV显示提示信息
		<body> <style type="text/css"> a.link{position:relative;} a.link div.tips{ bor ... 
- CSS:CSS使用Tips
		Css是前端开发中效果展现的主要部分之一,良好的Css书写习惯可以为实际的项目开发提高效率,也可以为实现良好的团队合作提供保证. 一般新手在使用Css的时候经常会犯一些错误,出现一些不经意的漏洞,如果 ... 
- 【读书笔记】100个Switf必备tips
		声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnblogs.com 农民伯伯: http://over140.cnblogs.com 正文 1.Selector 在Swi ... 
- 【转】40个良好用户界面Tips
		一个良好的用户界面应具有高转换率,并且易于使用.但要用户体验良好并不容易做到,下面我们整理了40个良好用户界面Tips,希望能对你有帮助! 1 尽量使用单列而不是多列布局 单列布局能够让对全局有更好的 ... 
- 转:Eclipse Search Tips
		from: https://github.com/ajermakovics/eclipse-instasearch/wiki/Eclipse-search-tips Eclipse Search T ... 
- VS:101 Visual Studio 2010 Tips
		101 Visual Studio 2010 Tips Tip #1 How to not accidentally copy a blank line TO – Text Editor ... 
- [css 揭秘]-css coding tips
		css 揭秘之css coding tips demo(1) html 代码: <body> <section> <div class="demo1" ... 
随机推荐
- poj 3522(最小生成树应用)
			题目链接:http://poj.org/problem?id=3522思路:题目要求最小生成树中最大边与最小边的最小差值,由于数据不是很大,我们可以枚举最小生成树的最小边,然后kruskal求最小生成 ... 
- C#基本语句
			1.创建个控制台应用程序(显示当前时间)然后在默认生成的Main函数里下如下代码:Console.WriteLine("显示当前时间:{0}",DateTime.Now.ToStr ... 
- BS与CS的比较
			http://www.oschina.net/news/57811/open-web-not-died?p=2#comments 浏览器是为浏览文档设计的,它的界面布局其实只有从上至下的流布局一种,浏 ... 
- Android笔记——Handler更新UI示例
			public class MainActivity extends ActionBarActivity { private TextView textView; private int i=0; @O ... 
- os  计算机的启动
			零.boot的含义 先问一个问题,”启动”用英语怎么说? 回答是boot.可是,boot原来的意思是靴子,”启动”与靴子有什么关系呢? 原来,这里的boot是bootstrap(鞋带)的缩写,它来自一 ... 
- POJ3176——Cow Bowling(动态规划)
			Cow Bowling DescriptionThe cows don't use actual bowling balls when they go bowling. They each take ... 
- Myeclipse 2014 javascript 添加 jquery 代码提示
			近日在写js,在myeclipse中没有jquery代码的提示着实不方便,在网上使用度娘搜索添加提示方式,试了多种,现经测试以下方式可取. 1.打开help菜单下的install from site. ... 
- hadoop中的ssh无密码登录配置
			在配置Hadoop集群分布时,要使用SSH免密码登录,假设现在有两台机器hadoop@Master(192.168.1.101),作为Master机,hadoop@Slave(192.168.1.10 ... 
- HDU 4638 Group 树状数组 + 思路
			实际上就是问这个区间编号连续的段的个数,假如一个编号连续的段有(a+b)个人,我把他们分在同一组能得到的分值为(a+b)^2,而把他们分成人数为a和b的两组的话,得到的分值就是a^2+b^2,显然(a ... 
- POJ -3050 Hopscotch
			http://poj.org/problem?id=3050 给定一个5×5矩阵,问选6个数的不同排列总数是多少! 二维的搜索,注意要判重,数据量很小,直接用map就好. #include<cs ... 
