Skip to content

Instantly share code, notes, and snippets.

@HybridDog
Created January 8, 2017 11:33
Show Gist options
  • Select an option

  • Save HybridDog/aeba934739beb29dc3b41892a55ed283 to your computer and use it in GitHub Desktop.

Select an option

Save HybridDog/aeba934739beb29dc3b41892a55ed283 to your computer and use it in GitHub Desktop.
on_chatmessage wraps
local t
minetest.register_on_chat_message(function()
t = minetest.get_us_time()
end)
for _ = 1,1000 do
minetest.register_on_chat_message(function() end)
end
minetest.register_on_chat_message(function()
print("direct: " .. minetest.get_us_time() - t .. " ms")
end)
local ocs = {}
local function ocw(func)
ocs[#ocs + 1] = func
end
minetest.register_on_chat_message(function()
t = minetest.get_us_time()
end)
minetest.register_on_chat_message(function(name, message)
for i = 1,#ocs do
if ocs[i](name, message) then
return
end
end
end)
for _ = 1,1000 do
ocw(function() end)
end
minetest.register_on_chat_message(function()
print("wrap: " .. minetest.get_us_time() - t .. " ms")
end)
@HybridDog
Copy link
Copy Markdown
Author

results
Note that ms should be µs there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment