Skip to content

Instantly share code, notes, and snippets.

@corarona
Created August 8, 2022 01:13
Show Gist options
  • Save corarona/c1fac12100e7cff01ab51b83ff531a46 to your computer and use it in GitHub Desktop.
Save corarona/c1fac12100e7cff01ab51b83ff531a46 to your computer and use it in GitHub Desktop.
localized lua vars test
-- test to check the time savings of localizing global functions
-- use /tgvars and /tlvars to run the tests for global and local
local vec = vector
local function do_testl(p)
local t0 = os.clock()
for i=1,65000 do for j=1,65000 do --for k=1,65000 do
local k = 5
local nv = vec.new(i,j,k)
local v = vec.add(p,nv)
local vm = vec.multiply(p,nv)
end end --end
return os.clock() - t0
end
local function do_testg(p)
local t0 = os.clock()
for i=1,65000 do for j=1,65000 do --for k=1,65000 do
local k = 5
local nv = vector.new(i,j,k)
local v = vector.add(p,nv)
local vm = vector.multiply(p,nv)
end end --end
return os.clock() - t0
end
minetest.register_chatcommand("tlvars",{func=function(n,param)
local p = minetest.get_player_by_name(n):get_pos()
return true,tostring(do_testl(p)*1000).."ms"
end})
minetest.register_chatcommand("tgvars",{func=function(n,param)
local p = minetest.get_player_by_name(n):get_pos()
return true,tostring(do_testg(p)*1000).."ms"
end})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment