mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-14 12:10:23 +07:00
Compare commits
2 Commits
3e4b0d02c1
...
2ed3be7a4a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ed3be7a4a | ||
|
|
a8fda4a22a |
@@ -1,5 +1,13 @@
|
||||
local basics = {}
|
||||
|
||||
local MIN_FUZZ_SECS = 0.5
|
||||
local MIN_BENCH_SECS = 0.1
|
||||
local MIN_WARMUP_SECS = 0.1
|
||||
|
||||
local MIN_FUZZ_ITERS = 100
|
||||
local MIN_BENCH_ITERS = 100
|
||||
local MIN_WARMUP_ITERS = 100
|
||||
|
||||
local __table_pack = (function()
|
||||
---@diagnostic disable-next-line: deprecated
|
||||
return table.pack or function(...)
|
||||
@@ -23,6 +31,8 @@ end
|
||||
|
||||
---@param modname string
|
||||
function basics.describe_fuzz(modname)
|
||||
basics.unload('evolved')
|
||||
|
||||
print(string.format('| %s ... |', modname))
|
||||
|
||||
collectgarbage('collect')
|
||||
@@ -39,7 +49,7 @@ function basics.describe_fuzz(modname)
|
||||
iters = iters + 1
|
||||
basics.unload(modname)
|
||||
require(modname)
|
||||
until os.clock() - start_s > 0.5
|
||||
until iters >= MIN_FUZZ_ITERS and os.clock() - start_s >= MIN_FUZZ_SECS
|
||||
end)
|
||||
|
||||
local finish_s = os.clock()
|
||||
@@ -65,17 +75,22 @@ end
|
||||
---@param init? fun(): ...
|
||||
---@param fini? fun(...): ...
|
||||
function basics.describe_bench(name, loop, init, fini)
|
||||
basics.unload('evolved')
|
||||
|
||||
print(string.format('| %s ... |', name))
|
||||
|
||||
local state = init and __table_pack(init()) or {}
|
||||
|
||||
do
|
||||
local iters = 0
|
||||
|
||||
local warmup_s = os.clock()
|
||||
|
||||
local success, result = pcall(function()
|
||||
repeat
|
||||
iters = iters + 1
|
||||
loop(__table_unpack(state))
|
||||
until os.clock() - warmup_s > 0.1
|
||||
until iters >= MIN_WARMUP_ITERS and os.clock() - warmup_s > MIN_WARMUP_SECS
|
||||
end)
|
||||
|
||||
if not success then
|
||||
@@ -97,7 +112,7 @@ function basics.describe_bench(name, loop, init, fini)
|
||||
repeat
|
||||
iters = iters + 1
|
||||
loop(__table_unpack(state))
|
||||
until os.clock() - start_s > 0.1
|
||||
until iters >= MIN_BENCH_ITERS and os.clock() - start_s > MIN_BENCH_SECS
|
||||
end)
|
||||
|
||||
local finish_s = os.clock()
|
||||
|
||||
Reference in New Issue
Block a user