One of the most important benefit of using vectors is performance, and ability to fixing memory.

Arrays are better in:

  • copying whole structure (Array to Array, using slice())
  • as a source to create typed Vector (using statement: Vector.<T>(sourceArray))

Vectors are better in:

  • iteration over collection by index
  • more familiar in IDE (auto-complete syntax of generic)

But what is the range of those benefits and how write program to see the difference?

test program:

That is true that vectors are faster. Output is as follow:

Array get properties: 2419ms
Vector get properties: 2360ms (~97%)

Hm, not so impressive. Let’s look at the code again. Oh, yes. I have forgotten about set fixed = true. Not is should be better. Let’s see.

Array get properties: 2334ms
Vector get properties: 2241ms (~96%).

Result is insignificant unfortunately. This is not so huge impact that I expect.

Les’s try another, most common example, when we must to process some value from array/vector and call several times to this value. To prevent constant accessing by index probably we use some temporary variable.

Current test loops:

And results:

Array get properties: 1138ms
Vector get properties: 913ms (~80%)

That is nice. But new question occurs now. If in most cases we storage local value why not use for each ? And in deed this loop consume 7% less CPU that for with local storage, but we lost index. Now everything is clear, we should use for each with fixed vectors to achieve best performance.


Flash Player is even smarter that I thought. Last example:

And results:

Vector get properties: 5937ms 
Vector get properties, foreach: 6063ms 


AVM is quite well optimized to work on indexes of tables/vectors and each next call to this index has no impact (impact is, but small) to the performance.

Local storage current element looks better, but is slower because of cost of allocation new variable.

0 Kudos