老外的一篇文章(原文地址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. **IOS:xib文件解析(xib和storyboard的比较,一个轻量级一个重量级)

    使用Xcode做iOS项目,经常会和Xib文件打交道,因为Xib文件直观的展现出运行时视图的外观,所以上手非常容易,使用也很方便,但对于从未用纯代码写过视图的童鞋,多数对Xib的理解有些片面. Xib ...

  2. C# 实现抓取网站页面内容

    抓取新浪网的新闻栏目,如图所示: 使用 谷歌浏览器的查看源代码: 通过分析得知,我们所要找的内容在以下两个标签之间: <!-- publish_helper name='要闻-新闻' p_id= ...

  3. poj 3635(bfs+优先队列)

    题目链接:http://poj.org/problem?id=3635 思路:本题主要运用的还是贪心思想,由于要求st->ed的最小花费,那么每经过一个城市,能不加油就尽量不加油,用dp[i][ ...

  4. MySQL 数据库存储引擎

    简单介绍 存储引擎就是指表的类型.数据库的存储引擎决定了表在计算机中的存储方式.存储引擎的概念是MySQl的特点,而且是一个插入式的存储引擎概念.这就决定了MySQl数据库中的表可以使用不同的存储方式 ...

  5. jquery常见问题

    1.下面哪种说法是正确的? 您的回答:jQuery 是 JavaScript 库 2.jQuery 使用 CSS 选择器来选取元素? 您的回答:错误 正确答案:正确 3.jQuery 的简写是? 您的 ...

  6. SSH乱码和Xshell异常断开解决方法

    一.SSH Secure Shell Client中文乱码的解决方法 这是SSH Secure Shell Client多年未解决的短板,要求客户端和服务器端都要‘UTF-8’编码,我终于知道Wind ...

  7. MongoDB (九) MongoDB 投影

    mongodb 投影意思是只选择必要的数据而不是选择一个文件的数据的整个.如果一个文档有5个字段,需要显示只有3个,然后选择其中只有3个字段. find() 方法 MongoDB 的find()方法, ...

  8. 欧拉工程第55题:Lychrel numbers

    package projecteuler51to60; import java.math.BigInteger; import java.util.Iterator; import java.util ...

  9. Qt中的多线程技术(列表总结比较,多线程创建和销毁其实是有开销的,只是增加了用户体验而已)

    http://blog.csdn.net/u011012932/article/details/52943811

  10. Qt 显示图片 放大 缩小 移动(都是QT直接提供的功能)

    本文章原创于www.yafeilinux.com 转载请注明出处. 现在我们来实现在窗口上显示图片,并学习怎样将图片进行平移,缩放,旋转和扭曲.这里我们是利用QPixmap类来实现图片显示的. 一.利 ...