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

  1. import flash.utils.getTimer;publicvar _time:Number;publicvar _simpleArrayTime:Number;publicvar buffer:Array;publicfunction testArray():void{
  2. trace("----------------Array Test--------------");
  3. _time = getTimer();for(var a:int=0; a <100000; a++)
  4. buffer =[];
  5. _simpleArrayTime = getTimer()- _time;
  6. trace("[] * 100000 :"+_simpleArrayTime.toPrecision(21));
  7. _time = getTimer();for(var b:int=0; b <100000; b++)
  8. buffer =newArray();
  9. _simpleArrayTime = getTimer()- _time;
  10. trace("new Array() * 100000 :"+_simpleArrayTime.toPrecision(21));
  11. _time = getTimer();for(var c:int=0; c <100000; c++)
  12. buffer =[];
  13. _simpleArrayTime = getTimer()- _time;
  14. trace("[] * 100000 :"+_simpleArrayTime.toPrecision(21));}publicvar objBuffer:Object;publicfunction testObject():void{
  15. trace("----------------Object Test--------------");
  16. _time = getTimer();for(var a:int=0; a <100000; a++)
  17. objBuffer ={};
  18. _simpleArrayTime = getTimer()- _time;
  19. trace("{} * 100000 :"+_simpleArrayTime.toPrecision(21));
  20. _time = getTimer();for(var b:int=0; b <100000; b++)
  21. objBuffer =newObject();
  22. _simpleArrayTime = getTimer()- _time;
  23. trace("new Object() * 100000 :"+_simpleArrayTime.toPrecision(21));
  24. _time = getTimer();for(var c:int=0; c <100000; c++)
  25. objBuffer ={};
  26. _simpleArrayTime = getTimer()- _time;
  27. trace("{} * 100000 :"+_simpleArrayTime.toPrecision(21));}publicfunction runTests(event:Event=null):void{
  28. testArray();
  29. testObject();
  30. }

----------------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

  1. 但在我本地的三次测试结果是这样的(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. 【转】dip,px,pt,sp 的区别

    dip: device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA.HVGA和QVGA 推荐使用这个,不依赖像素. ...

  2. 从.NET 1.1 升级到.NET 4.0 遇到 线程间操作无效: 从不是创建控件 [XX] 的线程访问它.

    有两种方式解决 1.在窗体构造函数中写Control.CheckForIllegalCrossThreadCalls =false;2.使用Invoke等委托函数 问题原因是 .NET2.0 以后拒绝 ...

  3. http://linuxme.blog.51cto.com/1850814/372960

    http://linuxme.blog.51cto.com/1850814/372960 http://os.51cto.com/art/201404/435129.htm

  4. Hadoop基础教程之分布式环境搭建

    前面,我们已经在单机上把Hadoop运行起来了,但我们知道Hadoop支持分布式的,而它的优点就是在分布上突出的,所以我们得搭个环境模拟一下. 在这里,我们采用这样的策略来模拟环境,我们使用3台ubu ...

  5. JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-002使用@Embeddable

    一.数据库 二.代码 1. package org.jpwh.model.simple; import javax.persistence.Column; import javax.persisten ...

  6. 关于Struts2的Validator的配置找不到DTD

    看教材的时候写的DTD是 <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.3//EN&q ...

  7. 阿里Druid数据库连接池使用

    阿里巴巴推出的国产数据库连接池,据网上测试对比,比目前的DBCP或C3P0数据库连接池性能更好 可以监控连接以及执行的SQL的情况. 加入项目的具体步骤: 1.导入jar <parent> ...

  8. 笔记一、Git服务器【转】

    传输协议: 本地传输,SSH协议,Git协议,HTTP协议   git clone /home/git/project.git                      // 本地clone git ...

  9. linux硬件驱动层

    1.make menuconfig scripts/kconfig/lxdialog/menubox.o: In function `print_buttons':menubox.c:(.text+0 ...

  10. PHP包含文件函数include、include_once、require、require_once区别总结

    一.使用语法和简介 1.include() 语法:include(/path/to/filename)include()语句将在其被调用的位置处包含一个文件.包含一个文件与在该语句所在位置复制制定文件 ...