core_assertions.rb: Refine assert_linear_performance

* Add `rehearsal` keyword argument
* Stop repeating with the same factor
This commit is contained in:
Nobuyoshi Nakada 2023-03-15 18:19:31 +09:00
parent ca437aeb39
commit 09041a6ee8
No known key found for this signature in database
GPG Key ID: 7CD2805BFA3770C6

View File

@ -738,17 +738,16 @@ eom
end
alias all_assertions_foreach assert_all_assertions_foreach
def assert_linear_performance(factor: 10_000, first: factor, max: 2, pre: ->(n) {n})
def assert_linear_performance(factor: 10_000, first: factor, max: 2, rehearsal: first, pre: ->(n) {n})
n = first
arg = pre.call(n)
tmax = (0..factor).map do
tmax = (0..rehearsal).map do
st = Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield arg
(Process.clock_gettime(Process::CLOCK_MONOTONIC) - st)
end.max
1.upto(max) do |i|
i += 1 if first >= factor
(first >= factor ? 2 : 1).upto(max) do |i|
n = i * factor
t = tmax * factor
arg = pre.call(n)