Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Are Vectors (indexed arrays) always faster than Arrays?

Engaged ,
Dec 19, 2013 Dec 19, 2013

When I say faster I mean less of a drain on performance.

Would an Vector be better than an Array when using an incursive array? Example:

var array:Array =

  [[1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1],

                                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1],

                                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],

                                        [1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1],

                                        [1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1],

                                        [0, 0, 0, 1, 0, 0, 0, 2, 0, 3, 0, 0, 0],

                                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1],

                                        [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],

                                        [1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1],

                                        [1, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 1],

                                        [1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1],

                                        [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],

                                        [1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1]];

Thanks!

TOPICS
ActionScript
700
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 19, 2013 Dec 19, 2013

When the data tends to be a built in type, not really. When you're using a class (as you are, an Array (class) of built in types), it can be faster. If your array is small and your calculations marginally complex it really won't make much difference on modern CPUs.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 19, 2013 Dec 19, 2013

So it's not much faster when using built in data types that aren't classes? I'm asking for clarity because an Array is a built in type and yet you say that my example would benifit from being a Vector instead of an Array.

so something like this would be better:

var vector:Vector.<Vector.<uint>> = new Vector.<Vector.<uint>>();

But this wouldn't make much of a difference:

var vector:Vector.<uint> = new Vector.<uint>();

What about Objects and Points? Would those be better in a Vector or an Array?

Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 19, 2013 Dec 19, 2013

You're reading me correctly but the Array class contains complex values, not primitive values. Types like Boolean, int, Number, String, etc. are faster due to primitive values being internally stored as immutable. Complex values are mutable and dynamic, like Array, Date, Error, Function, etc..

A Vector can speed up large amounts of calculations on objects with complex values. So yes, Objects that contain complex values such as a Point can speed up. However if you're literally not processing hundreds of thousands to millions of calculations the performance difference will be negligible on any modern CPU.

There's Adobe articles on simple benchmarks:

http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c3a0f5f19124318fc87b-7fff.html

And plenty of random tests from people performing large number iterations, posting performance differences. Some random link:

http://loteixeira.github.io/test/2013/02/16/array-vs-vector/

To accurately answer you, you really need to test a large number of iterations on the calculations and data YOU want to work with to see which makes more sense.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 20, 2013 Dec 20, 2013

Where you really gain speed with a Vector is not having to cast or type-check things

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 23, 2013 Dec 23, 2013
LATEST

Almost double performance in certain operations when you specify a fixed size for your Vector. All these things draw you closer to immutable performance.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines