Performance Comparisons


We're now going to look at some performance comparisons of a fixed array vs other objects.

Important Note: Computer performance timings are ballpark estimates. We should only use them to get a general "feel" for an operation(s). We'll learn more about this when we study "Big-O" which does not use performance timings.

Here are some timings recently we did on an average desktop computer:

OperationStructure SizeOperations/
Millisecond
DescriptionNote
Increment an integer (a trivial operation1 Millioncount++An operation that can generally be ignored (is insignificant) in a performance analsyis
Toggle UI element visibility10show elem if hidden, hide elem if visible
Indexed access of fixed arrayArray size 10001 Millionarray[index]
Indexed access of fixed arrayArray size 10 Million1 Millionarray[index]


Advantages


Given the performance comparisons above, let's ask ourselves a couple questions about our observations.

How does the fixed array indexed access compare to the trivial operation of incrementing an integer?

The fixed array performs similarily to a trivial computer operation (e.g. count++)!

This is the first BIG ADVANTAGE of a fixed array. Indexed access performance is superb.
How does fixed array size (i.e. number of elements) impact indexed access performance?

If a fixed array grows in size from one thousand to ten million the performance remains the same!

This is the second BIG ADVANTAGE of a fixed array. Array size has no effect.
How does the fixed array indexed access compare to toggling the visibility of a UI element?

The fixed array indexed access performs 100,00 times faster than the UI operation.

And this about as simple as an UI operation as there can be (simply showing or hiding one element).


Big-O Notation O(1)


We just learned our first piece of Big-O notation -- when we have an algorithm that has constant performance no matter the structure size (small or very large) -- we call this O(1), which means constant performance.

The digit "1" does not have a numeric meaning -- it simply signifies "constant".


Disadvantages


Let's now take a guess at a disadvantages of a "fixed array" (hint: the name gives it away).

What is the primary disadvantage of a fixed array?

That it is fixed (in size).

We do not have the ability to add (append or insert) or re
move elements.

This is the BIG DISADVANTAGE of a fixed array. The structure is not dynamic or flexible.

Given a fixed array:

array = ['Suni', 'Simone', 'Liu', 'Jade', 'Tin', 'Artur'];


If we wanted to add a new name or remove a name, we would be out of luck.