Is indexing a smaller table faster than a bigger table?

Lets say we have two dictionaries or arrays. One has 5 variables and the other has 20 variables. Is indexing the table that has 5 variables generally faster and might this change if the intensity of indexing increased, for example to 2 times per second? Can the fact that the table is an array or a dictionary influence that too?

I don’t think the difference is significant. But you could check it by printing before and after looping through a table.

There is a very small to no difference, it is at a 0.0000001s difference, something like that… unless your table have hundreds or thousands of variables, it’s fine.

The rate of how much time you’re indexing the table per second do not change anything to the speed.

And same for array and dictionary, there is a very small to no difference between both, you shouldn’t worry about it.

In general, indexing a smaller table would tend to be faster than indexing a larger one, assuming all other factors remain constant. Searching through a smaller dataset typically requires less computing time.

Traditional array access is always constant time–as is to say, irrespective of array length. Associative lookups are usually also constant, but can technically run the risk of hash collisions. In practice, these are exceedingly rare, and are always handled with a negligible sacrifice to performance. No matter the circumstance, indexing in Lua/u is so cheap as to largely not be regarded. In my experience designing algorithms, the arithmetic to generate indices tends to be more expensive than the index operations themselves.

3 Likes