local LuaProfiler = {} -- --TODO 实现一个机制能够分别查看每个模块的内存增长 -- local _require = require -- local function require(name, ...) -- local before = collectgarbage('count') -- local mod =_require(name, ...) -- local after = collectgarbage("count") -- local diff = after - before -- if diff > 128 then -- print(name, '+', diff/1024, after/1024) -- end -- return mod -- end function LuaProfiler.SampleMemory(mod) local k = string.gsub(mod, "/", ".") package.loaded[k] = nil collectgarbage() local count = collectgarbage("count") require(mod) return collectgarbage("count") - count end function LuaProfiler.SampleTime(repTimes, func, ...) local start = os.clock() for i = 1, repTimes or 1 do func(...) end local stop = os.clock() return math.modf((stop - start) * 1000) end return LuaProfiler