EDIT
My original answer was wrong except for the very last part, and I have to apologize for that. I knew for a fact that Vector has exactly four implementations "under the hood". (You can find decompiled sources from FP 10 playerglobal.swc in a post by Robert Penner here) Three of those are for number types (int, uint and Number). One is for Object types. This last one serves as a catch-all and takes in all classes derived from Object. This is why I assumed that Vector.<Object>
was still faster than Array, relying on the information regarding vectors and arrays available from Adobe.
However, it seems that this information is wrong, or at least it leaves out some important parts:
While Vector.<AnyClassDerivedFromObject>
allows for strict typing, this type information is only evaluated at compilation time (so you get more type safety), but not at runtime - thus essentially the benefits of strict typing object vectors do not apply to performance. See this blog post for more info.
Consequently, the only implementations of Vector that are faster than Array are the ones for number types (!).
In fact, I have done some extensive testing on this, and have come to the conclusion that while Vector.<int>
is up to 60% faster than Array of ints, all the derivates of Vector.<Object>
are not only equal in speed (i.e. Vector.<Object>
performs the same as Vector.<String>
, they also are about 20% slower than Array. I've double- and triple-checked this, so I believe the results to be fairly accurate.
It still is true that the number type vectors are faster, so you should use those for performance benefits over Array. But:
END EDIT
Only if you're going to use sort()
, sortOn()
or any other of the convenient sorting functions of Array, you might still decide otherwise, because these are native functions, and as such really fast. Implementing your own sorting methods on a Vector will probably not match their speed.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…