Flex——Array,ArrayCollection,Vector性能比较

测试方法

private function Test():void

{

    for(var j:int=0;j<5;j++)

    {

        trace("插入10000项============");

        var t1:int, t2:int;

        var i:int = 0;

        var a:Array = new Array();

        var al:ArrayCollection = new ArrayCollection();

        var item:String;

        var v:Vector.<String> = new Vector.<String>();

        

        t1 = getTimer();

        for(i=0;i<10000;i++)

            a.push(StringUtil.NewGuid());    

        t2 = getTimer();

        trace("Array耗时:/t/t",t2-t1);

        

        t1 = getTimer();

        for(i=0;i<10000;i++)

            al.addItem(StringUtil.NewGuid());    

        t2 = getTimer();

        trace("ArrayCollection耗时:/t",t2-t1);

        

        t1 = getTimer();

        for(i=0;i<10000;i++)

            v.push(StringUtil.NewGuid());

        t2 = getTimer();

        trace("Vector耗时:/t/t",t2-t1);

        

        trace("");

        trace("遍历10000项==========");

        

        t1 = getTimer();

        for(i=0;i<10000;i++)

            item = a[0];

        t2 = getTimer();

        trace("Array耗时:/t/t",t2-t1);

        

        t1 = getTimer();

        for(i=0;i<10000;i++)

            item = al[0];

        t2 = getTimer();

        trace("ArrayCollection耗时:/t",t2-t1);

        

        t1 = getTimer();

        for(i=0;i<10000;i++)

            item = v[0];

        t2 = getTimer();

        trace("Vector耗时:/t/t",t2-t1);

        trace("");

    }

}

测试输出

插入10000项============

Array耗时:         465

ArrayCollection耗时:     788

Vector耗时:         444

 

遍历10000项==========

Array耗时:         2

ArrayCollection耗时:     98

Vector耗时:         2

 

插入10000项============

Array耗时:         433

ArrayCollection耗时:     791

Vector耗时:         430

 

遍历10000项==========

Array耗时:         2

ArrayCollection耗时:     97

Vector耗时:         2

 

插入10000项============

Array耗时:         427

ArrayCollection耗时:     805

Vector耗时:         415

 

遍历10000项==========

Array耗时:         1

ArrayCollection耗时:     97

Vector耗时:         1

 

插入10000项============

Array耗时:         422

ArrayCollection耗时:     824

Vector耗时:         401

 

遍历10000项==========

Array耗时:         2

ArrayCollection耗时:     97

Vector耗时:         2

 

插入10000项============

Array耗时:         467

ArrayCollection耗时:     772

Vector耗时:         438

 

遍历10000项==========

Array耗时:         2

ArrayCollection耗时:     98

Vector耗时:         2

结论

Array与Vector性能接近,插入时Vector略快,遍历相近,Vector的优点是强类型,缺点是要Flash Player 10,所以作数据存储运算等建议使用Array。

ArrayCollection性能最差,插入时约比Array慢了一倍,遍历慢了几十倍,ArrayCollection的优势是界面的数据绑定以及支持数据排序等高级方法。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值