How important is time complexity

I have two tables, one is of unknown size, 0 to 166, the other of size 166. I start at the first index of the unknown sized table, and see if the element is the table of size 166. Then I continue until I reach the end of unknown sized table. This double for loop way is an inefficient way of doing it. This script runs when the player joins the game. Is it worth fixing or pretty unimportant given that it’s not a super large number of comparisons?

2 Likes

My understanding is that you have this situation:

local t1 = {}--where #t1 = n
local t2 =  {} --where #t2 = 166

Both are unsorted array like tables and you need to find out if elements in t1 are in t2.
Slight variation:

for i,v in t1 do
    if table.find(t2, v) then
        print("found", v)
    end
end

You could try timing it, but if this will only run once I think it’s probably not worth the effort looking for micro-optimisations.

1 Like