Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- gmod luajit
- local function Benchmark(uid, func, count, onfinish)
- timer.Simple(0, function() -- 1 tick delay
- local start = SysTime()
- for i = 1, count do
- func()
- end
- print(uid, SysTime() - start)
- if onfinish then onfinish() end
- end)
- end
- local function Bench()
- local bench = {
- process = {},
- Start = function(self, count)
- self.count = count
- self:Run()
- end,
- Run = function(self, id, onfinish)
- id = (id or 0) + 1
- local process = self.process[id]
- if process == nil then return end
- Benchmark(process.uid, process.func, self.count, function()
- self:Run(id)
- end)
- end,
- Add = function(self, uid, func)
- table.insert(self.process, {uid = uid, func = func})
- return self
- end
- }
- bench.__index = bench
- return bench
- end
- local tbl = {"one", "two", "three", "four", "five"}
- Bench()
- :Add("for i = 1, #tbl do", function()
- for i = 1, #tbl do
- local v = tbl[i]
- end
- end)
- :Add("for i, v in ipairs(tbl) do", function()
- for i, v in ipairs(tbl) do
- end
- end)
- :Start(10000000) -- 10 000 000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement