Skip to content

Instantly share code, notes, and snippets.

@rgrams
Created October 24, 2017 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgrams/79f18974435e534d847069440f1669b1 to your computer and use it in GitHub Desktop.
Save rgrams/79f18974435e534d847069440f1669b1 to your computer and use it in GitHub Desktop.
Iterative performance tester for Lua functions in Defold.
-- Functions to test
local function norm_call(id)
return go.get_position(id)
end
local function safe_call(id)
return pcall(go.get_position, id)
end
--################################################################################
local iter = 1000000
local function run_test(func, name, ...)
local t = socket.gettime()
for i=1, iter do
func(...)
end
print(string.format("Function '%s' took %.5f ms", name, (socket.gettime() - t)*1000))
end
function init(self)
msg.post(".", "acquire_input_focus")
-- call run_test here
local id = go.get_id()
run_test(norm_call, "normal call", id)
run_test(safe_call, "safe call", id)
end
function on_input(self, action_id, action)
if action_id == hash("escape") and action.pressed then
msg.post("@system:", "exit", {code = 0})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment