老外的一篇文章(原文地址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的更多相关文章

  1. Mac上MySQL忘记root密码且没有权限的处理办法&workbench的一些tips (转)

    忘记Root密码肿么办 Mac上安装MySQL就不多说了,去mysql的官网上下载最新的mysql包以及workbench,先安装哪个影响都不大.如果你是第一次安装,在mysql安装完成之后,会弹出来 ...

  2. 【Tips】史上最全H1B问题合辑——保持H1B身份终级篇

    [Tips]史上最全H1B问题合辑——保持H1B身份终级篇 2015-04-10留学小助手留学小助手 留学小助手 微信号 liuxue_xiaozhushou 功能介绍 提供最真实全面的留学干货,帮您 ...

  3. layer.js中layer.tips

    <script src="~/Content/js/layer/layer.js"></script> layer.tips('名称不能为空', '#pro ...

  4. HTML 最简单的tips 怎么支持指定DIV显示提示信息

    <body> <style type="text/css"> a.link{position:relative;} a.link div.tips{ bor ...

  5. CSS:CSS使用Tips

    Css是前端开发中效果展现的主要部分之一,良好的Css书写习惯可以为实际的项目开发提高效率,也可以为实现良好的团队合作提供保证. 一般新手在使用Css的时候经常会犯一些错误,出现一些不经意的漏洞,如果 ...

  6. 【读书笔记】100个Switf必备tips

    声明 欢迎转载,但请保留文章原始出处:)  博客园:http://www.cnblogs.com 农民伯伯: http://over140.cnblogs.com 正文 1.Selector 在Swi ...

  7. 【转】40个良好用户界面Tips

    一个良好的用户界面应具有高转换率,并且易于使用.但要用户体验良好并不容易做到,下面我们整理了40个良好用户界面Tips,希望能对你有帮助! 1 尽量使用单列而不是多列布局 单列布局能够让对全局有更好的 ...

  8. 转:Eclipse Search Tips

    from:  https://github.com/ajermakovics/eclipse-instasearch/wiki/Eclipse-search-tips Eclipse Search T ...

  9. VS:101 Visual Studio 2010 Tips

    101 Visual Studio 2010 Tips Tip #1        How to not accidentally copy a blank line TO – Text Editor ...

  10. [css 揭秘]-css coding tips

    css 揭秘之css coding tips demo(1) html 代码: <body> <section> <div class="demo1" ...

随机推荐

  1. Codeforces Round #262 (Div. 2) A B C

    题目链接 A. Vasya and Socks time limit per test:2 secondsmemory limit per test:256 megabytesinput:standa ...

  2. 深入理解Windows X64调试

    随着64位操作系统的普及,都开始大力进军x64,X64下的调试机制也发生了改变,与x86相比,添加了许多自己的新特性,之前学习了Windows x64的调试机制,这里本着“拿来主义”的原则与大家分享. ...

  3. C#获取当前路径的方法

    C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName -获取模块的完整路径. 2. ...

  4. 与Wii控制手柄通信的托管代码库(转)

    2009-01-16 翻译 HID Human Input Device     人工输入设备 Wii Fit Balance Board       平衡板 IR                   ...

  5. C#程序大打开

    打开一个已经存在的工程: 1.用vs打开(.sln)解决方案的文件.(若提示VS提示版本不一致,可用方法二) 2.删除(.sln)的文件.打开项目(.csproj) 文件或 (.vbproj) 文件, ...

  6. Struts2笔记——类型转换

     概述 * 从一个HTML 表单到一个Action 对象, 类型转换是从字符串到非字符串.     >HTTP 没有 “类型” 的概念. 每一项表单输入只可能是一个字符串或一个字符串数组. 在服 ...

  7. CentOS增加硬盘

    1.查看新硬盘     #fdisk –l      新添加的硬盘的编号为/dev/sdb 2.硬盘分区     1)进入fdisk模式     #/sbin/fdisk /dev/sdb     2 ...

  8. 资源 之 4.4 Resource通配符路径 ——跟我学spring3

    4.4.1  使用路径通配符加载Resource 前面介绍的资源路径都是非常简单的一个路径匹配一个资源,Spring还提供了一种更强大的Ant模式通配符匹配,从能一个路径匹配一批资源. Ant路径通配 ...

  9. scroll 事件绑定

    var animateBlock={        isVisiable:function(el,wh,st,delta){            delta=delta||200;          ...

  10. poj -2010 Moo University - Financial Aid (优先队列)

    http://poj.org/problem?id=2010 "Moo U"大学有一种非常严格的入学考试(CSAT) ,每头小牛都会有一个得分.然而,"Moo U&quo ...