Created
October 24, 2017 13:04
-
-
Save rgrams/79f18974435e534d847069440f1669b1 to your computer and use it in GitHub Desktop.
Iterative performance tester for Lua functions in Defold.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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