Local variable in function

There is a cost associated with creating new url objects, and a slight difference if you reuse hashes. In tight loops this may matter. On my machine i get the following results on 1 million iterations. The difference may be bigger or smaller on a handheld.

for i=1,1000000 do
	test(msg.url("hello"))
end
-- 0.78450298309326 seconds
local h = hash("/hello")
for i=1,1000000 do
	test(msg.url(h))
end
-- 0.61077499389648 seconds
local url = msg.url("hello")
for i=1,1000000 do
	test(url)
end
-- 0.10395789146423 seconds
7 Likes