For some time now I have been trying to prove some statements about performance with facts, that is, through benchmarking.
So far I have the following (they are few, but they help anyone who wants to be sure about performance comparisons):
Just to be fair, in the original test I purposely sent table.find to look for the last item in the table, so it had to loop internally 30000 times until it found the result.
So, I changed the item to be searched: instead of the last, the first; in this way table.find will immediately find the first item.
Even so, table.find proved to be 5 times slower than searching for an index in a dictionary:
table and dictionary with 30000 elements
key to find in both: k1
seconds to find a key i…
Just to confirm that functions declared as Local are REALLY faster than global functions, I created a benchmark below:
local elements = 100000000
local keyToFind = "k" .. elements
function GlobalFunction()
return true
end
local function LocalFunction()
return true
end
-- benchmark
local time = tick()
for i = 1, elements do
GlobalFunction()
end
local timeG = tick() - time
print("seconds to run a Global function:\t", timeG)
local time = tick()
for i = 1, elements do
LocalFunction()
end…
2 Likes