Created
October 11, 2019 09:04
-
-
Save ochaton/6860284b6cc1d612c383c6b5b434e611 to your computer and use it in GitHub Desktop.
LuaJIT + Big Tables + GC
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
#!/usr/bin/luajit-5_1-2.1.0-beta3 | |
local print = print | |
local collectgarbage = collectgarbage | |
local pairs = pairs | |
local tostring = tostring | |
local module = module | |
do | |
for k in pairs(package) do | |
package[k] = nil | |
end | |
_G = {} | |
module("") | |
end | |
local gcinfo = function() | |
return collectgarbage('count') | |
end | |
local function pgc(prefix) | |
print(prefix or "", gcinfo()) | |
end | |
collectgarbage('collect') | |
pgc("init") --> init 28.09375 | |
local tbl = {} | |
local i = 1 | |
while i < 10000000 do | |
tbl[tostring(i)] = true | |
i = i + 1 | |
end | |
pgc("after while") --> after while 692069.73828125 | |
collectgarbage('collect') | |
pgc("after 1st collect") --> after 1st collect 692069.41015625 | |
collectgarbage('collect') | |
pgc("after 2nd collect") --> after 2nd collect 692069.41015625 | |
for key in pairs(tbl) do | |
tbl[key] = nil | |
end | |
pgc("after 1st for") --> after 1st for 692069.41015625 | |
collectgarbage('collect') | |
pgc("collect 1") --> collect 1 426011.49609375 | |
collectgarbage('collect') | |
pgc("collect 2") --> collect 2 401435.49609375 | |
for key in pairs(tbl) do | |
print("< ", key) | |
end | |
pgc("after 2nd for") --> after 2nd for 401435.49609375 | |
tbl = nil | |
collectgarbage('collect') | |
pgc("after 1st collect") --> after 1st collect 2075.46484375 | |
collectgarbage('collect') | |
pgc("after 2nd collect") --> after 2nd collect 539.46484375 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment