mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-15 04:15:28 +07:00
add min fuzz/bench iters and time
This commit is contained in:
@@ -1,5 +1,13 @@
|
|||||||
local basics = {}
|
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()
|
local __table_pack = (function()
|
||||||
---@diagnostic disable-next-line: deprecated
|
---@diagnostic disable-next-line: deprecated
|
||||||
return table.pack or function(...)
|
return table.pack or function(...)
|
||||||
@@ -39,7 +47,7 @@ function basics.describe_fuzz(modname)
|
|||||||
iters = iters + 1
|
iters = iters + 1
|
||||||
basics.unload(modname)
|
basics.unload(modname)
|
||||||
require(modname)
|
require(modname)
|
||||||
until os.clock() - start_s > 0.5
|
until iters >= MIN_FUZZ_ITERS and os.clock() - start_s >= MIN_FUZZ_SECS
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local finish_s = os.clock()
|
local finish_s = os.clock()
|
||||||
@@ -70,12 +78,15 @@ function basics.describe_bench(name, loop, init, fini)
|
|||||||
local state = init and __table_pack(init()) or {}
|
local state = init and __table_pack(init()) or {}
|
||||||
|
|
||||||
do
|
do
|
||||||
|
local iters = 0
|
||||||
|
|
||||||
local warmup_s = os.clock()
|
local warmup_s = os.clock()
|
||||||
|
|
||||||
local success, result = pcall(function()
|
local success, result = pcall(function()
|
||||||
repeat
|
repeat
|
||||||
|
iters = iters + 1
|
||||||
loop(__table_unpack(state))
|
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)
|
end)
|
||||||
|
|
||||||
if not success then
|
if not success then
|
||||||
@@ -97,7 +108,7 @@ function basics.describe_bench(name, loop, init, fini)
|
|||||||
repeat
|
repeat
|
||||||
iters = iters + 1
|
iters = iters + 1
|
||||||
loop(__table_unpack(state))
|
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)
|
end)
|
||||||
|
|
||||||
local finish_s = os.clock()
|
local finish_s = os.clock()
|
||||||
|
|||||||
Reference in New Issue
Block a user