老外的一篇文章(原文地址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. MYSQL - ORDER BY & LIMIT

    http://stackoverflow.com/questions/4708708/mysql-order-by-limit

  2. Java获取最后插入MySQL记录的自增ID值方法

    方法一: String sql = "INSERT INTO users (username,password,email) VALUES (?,?,?);"; PreparedS ...

  3. HDU5569/BestCoder Round #63 (div.2) C.matrix DP

    matrix Problem Description Given a matrix with n rows and m columns ( n+m is an odd number ), at fir ...

  4. Linux中ping命令

    Linux系统的ping命令是常用的网络命令,它通常用来测试与目标主机的连通性,我们经常会说“ping一下某机器,看是不是开着”.不能打开网页时会说“你先ping网关地址192.168.1.1试试”. ...

  5. 01 - 开发成功的Oracle应用

    笔记 1. 开发数据库应用,不能把数据库当黑盒.需要了解数据库的一下内容 数据库的体系结构 并发控制 开发的时候就要调优你的代码 数据库有哪些特性,不要在你的代码里重复实现 深入的学习SQL 2. 我 ...

  6. (转载)C++ ofstream和ifstream详细用法

    原文出自[比特网],转载请保留原文链接:http://soft.chinabyte.com/database/460/11433960.sh [导读] ofstream是从内存到硬盘,ifstream ...

  7. Markdown语法和MWeb使用说明

    Markdown 语法和 MWeb 写作使用说明 开始写博客,首先熟悉一下Markdown,以前过看GitHub里的README.MD,感受到了这种文字排版的简洁美观. 写博客是一种有效的学习总结和分 ...

  8. ajax:serialize() 获取表单集合

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. HtmlAgilityPackage XPath学习

    最近的开发中要用到htmlAgilityPackage, 所以记录一下XPath相关知识! XPath 简介 XPath 是一门在 XML 文档中查找信息的语言.XPath 可用来在 XML 文档中对 ...

  10. IOS 的loadView 及使用loadView中初始化View注意的问题。(死循环并不可怕)

    在XCode 4.2后,我基本上的应用都不使用Xib文件了,虽然xib文件有很多好趣,可以快速免代码构建视窗,可以减少好多代码构建带来的麻烦,其实能用xib还是不错的,主要是我的机器打开xib来编辑时 ...