# Speed test for looping through array (trick from PHP)

**URL:** <https://forum.kirupa.com/t/speed-test-for-looping-through-array-trick-from-php/302220>\
**Category:** flash\
**Created:** [December 23, 2009, 5:51pm UTC](https://forum.kirupa.com/t/speed-test-for-looping-through-array-trick-from-php/302220 "2009-12-23T17:51:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shaedo](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@Shaedo](https://forum.kirupa.com/u/Shaedo)\
**Post date:** [December 23, 2009, 5:51pm UTC](https://forum.kirupa.com/t/speed-test-for-looping-through-array-trick-from-php/302220/1 "2009-12-23T17:51:23Z")

</div>

Hi, so on the PHP site it was advised to do for loops in a certain way that I have not seen on any recommendations for AS3. I think I found about a 10 times speed increase and I thought I better **check that I was not missing something (?)** before going through my code and changing it. Very simple and fairly self explanatory (in the faster one the array.length is not calculated every time I think):

```auto
import flash.utils.getTimer;
var time:Number;
var myarray:Array = new Array();
myarray.length=2000000;

time=getTimer();
for(var i:uint=0, j:uint=myarray.length; i<j; i++)
{}
trace(getTimer()-time);//11

time=getTimer();
for(var k:uint=0; k<myarray.length; k++)
{}
trace(getTimer()-time);//112

```
