mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-14 12:10:23 +07:00
fix bench basics
This commit is contained in:
@@ -14,42 +14,54 @@ end)()
|
||||
---@param loop fun(...): ...
|
||||
---@param init? fun(): ...
|
||||
function basics.describe_bench(name, loop, init)
|
||||
print(string.format('| %s ... |', name))
|
||||
|
||||
local state = init and __table_pack(init()) or {}
|
||||
|
||||
do
|
||||
local warmup_s = os.clock()
|
||||
|
||||
local success, result = pcall(function()
|
||||
repeat
|
||||
loop(__table_unpack(state))
|
||||
until os.clock() - warmup_s > 0.1
|
||||
end)
|
||||
|
||||
if not success then
|
||||
print('|-- FAIL: ' .. result)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
collectgarbage('collect')
|
||||
collectgarbage('stop')
|
||||
|
||||
print(string.format('| %s ... |', name))
|
||||
do
|
||||
local iters = 0
|
||||
|
||||
local iters = 0
|
||||
local state = init and __table_pack(init()) or {}
|
||||
local start_s = os.clock()
|
||||
local start_kb = collectgarbage('count')
|
||||
|
||||
pcall(function()
|
||||
local warmup_s = os.clock()
|
||||
repeat
|
||||
loop(__table_unpack(state))
|
||||
until os.clock() - warmup_s > 0.1
|
||||
end)
|
||||
local success, result = pcall(function()
|
||||
repeat
|
||||
iters = iters + 1
|
||||
loop(__table_unpack(state))
|
||||
until os.clock() - start_s > 0.1
|
||||
end)
|
||||
|
||||
local start_s = os.clock()
|
||||
local start_kb = collectgarbage('count')
|
||||
local finish_s = os.clock()
|
||||
local finish_kb = collectgarbage('count')
|
||||
|
||||
local success, result = pcall(function()
|
||||
repeat
|
||||
iters = iters + 1
|
||||
loop(__table_unpack(state))
|
||||
until os.clock() - start_s > 0.1
|
||||
end)
|
||||
|
||||
local finish_s = os.clock()
|
||||
local finish_kb = collectgarbage('count')
|
||||
|
||||
print(string.format(' %s | us: %.2f | op/s: %.2f | kb/i: %.2f | iters: %d',
|
||||
success and 'PASS' or 'FAIL',
|
||||
(finish_s - start_s) * 1e6 / iters,
|
||||
iters / (finish_s - start_s),
|
||||
(finish_kb - start_kb) / iters,
|
||||
iters))
|
||||
|
||||
if not success then print(' ' .. result) end
|
||||
if success then
|
||||
print(string.format('|-- PASS | us: %.2f | op/s: %.2f | kb/i: %.2f | iters: %d',
|
||||
(finish_s - start_s) * 1e6 / iters,
|
||||
iters / (finish_s - start_s),
|
||||
(finish_kb - start_kb) / iters,
|
||||
iters))
|
||||
else
|
||||
print('|-- FAIL: ' .. result)
|
||||
end
|
||||
end
|
||||
|
||||
collectgarbage('restart')
|
||||
collectgarbage('collect')
|
||||
|
||||
Reference in New Issue
Block a user