PDA

View Full Version : Object and Array can BOTH function as arrays ? Which one is faster ?


Amn
01-23-2004, 06:04 AM
Sorry I am asking way too many questions and give way too little answers, but....

Flash says Array is native now and is improved in performance, but what does it really mean ?

Here is an array implemented as Object. No reference to Array class. This is looking much like property lookup, where property is numerically identified:


var o = new Object;

o[0] = "helo";


And consider this example, which is the same as above but with native Array:


var o = new Array;

o[0] = "helo";


Are there any differences in performance between the two ? Does Flash documentation really mean that, although numeric property lookup is supported in any object, it is much faster when used with Array ?

phoolish
01-23-2004, 11:49 AM
I have not noticed any difference in speed?, but then again, I've only been using actionscript 2 for a week now. Any uber geeks tested out the performance qualities on the array()?

Amn
01-23-2004, 12:09 PM
I have tested and the speed seems to be equal.

phoolish
01-23-2004, 12:13 PM
what did you do to test them?

Amn
01-23-2004, 12:17 PM
for(var i = 0; i < 50000; i++)
a[i] = i;

for(var i = 0; i < 50000; i++)
trace(a[i]);

//a being an Array and an Object.


The time this script takes to generate output is about the same.
I know this is at best rough benchmarking, but when 50000 items (only 38000 or so have been successfully output for) are printed out at approximately the same speed, it makes me confident ;)