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" ...
随机推荐
- 离开csdn来到blog园
csdn里没有限制阅读访问的功能,所以我选择来到cnblog 但是不得不说,cnblog做的界面很丑,我个人很不喜欢,但是没办法
- interviewbit : Max Non Negative SubArrayBookmark Suggest Edit
Find out the maximum sub-array of non negative numbers from an array.The sub-array should be continu ...
- java多线程知识点总结
1.线程调度知识:线程类Thread的了解,几个thread的方法.thread.sleep(),thread.join().(调用join方法的那个线程会立刻执行). object.wait()方法 ...
- Maven的安装
我对maven的了解,仅仅局限在百度百科. 由于近期公司需求,我找到了个maven教程:http://wentao365.iteye.com/blog/903396 安装maven其实很简单,就是在A ...
- python 详解re模块
正则表达式的元字符有. ^ $ * ? { [ ] | ( ).表示任意字符[]用来匹配一个指定的字符类别,所谓的字符类别就是你想匹配的一个字符集,对于字符集中的字符可以理解成或的关系.^ 如果放在字 ...
- STM32F05x加入RDP(LV1)后,Segger无法Unlock的解决办法
沿用之前CM3核的STM32F10X系列的加入RDP功能,之后在Segger的Unsecured Chip或者Unlock STM32的Cmd无法进行去除RDP,而Unlock STM32则提示无法识 ...
- ORACLE基本语法
ORACLE基本语法 一.ORACLE的启动和关闭1.在单机环境下要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下su - oraclea.启动ORACLE系统oracle>s ...
- 【转】RESTful Web Services初探
近几年,RESTful Web Services渐渐开始流行,大量用于解决异构系统间的通信问题.很多网站和应用提供的API,都是基于RESTful风格的Web Services,比较著名的包括Twit ...
- CentOS7区域设置
区域设置的配置文件在/etc/locale.conf,通过localectl命令进行设置: systemd服务在启动的时候读取区域配置文件,完成系统的设置. 命令的几个常用方法如下: 1 查看当前配置 ...
- LINUX内核分析第四周学习总结——扒开应用系统的三层皮(上)【转】
转自:http://www.cnblogs.com/lalacindy/p/5276874.html 张忻(原创作品转载请注明出处) <Linux内核分析>MOOC课程http://moo ...