core_assertions.rb: Extract common code block
This commit is contained in:
parent
f07c756494
commit
f9eb2515a3
Notes:
git
2023-04-05 15:19:24 +00:00
@ -746,15 +746,18 @@ eom
|
|||||||
def assert_linear_performance(seq, rehearsal: nil, pre: ->(n) {n})
|
def assert_linear_performance(seq, rehearsal: nil, pre: ->(n) {n})
|
||||||
# Timeout testing generally doesn't work when RJIT compilation happens.
|
# Timeout testing generally doesn't work when RJIT compilation happens.
|
||||||
rjit_enabled = defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled?
|
rjit_enabled = defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled?
|
||||||
|
measure = proc do |arg, message|
|
||||||
|
st = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||||
|
yield(*arg)
|
||||||
|
t = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - st)
|
||||||
|
assert_operator 0, :<=, t, message unless rjit_enabled
|
||||||
|
t
|
||||||
|
end
|
||||||
|
|
||||||
first = seq.first
|
first = seq.first
|
||||||
*arg = pre.call(first)
|
*arg = pre.call(first)
|
||||||
times = (0..(rehearsal || (2 * first))).map do
|
times = (0..(rehearsal || (2 * first))).map do
|
||||||
st = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
measure[arg, "rehearsal"].nonzero?
|
||||||
yield(*arg)
|
|
||||||
t = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - st)
|
|
||||||
assert_operator 0, :<=, t unless rjit_enabled
|
|
||||||
t.nonzero?
|
|
||||||
end
|
end
|
||||||
times.compact!
|
times.compact!
|
||||||
tmin, tmax = times.minmax
|
tmin, tmax = times.minmax
|
||||||
@ -767,9 +770,7 @@ eom
|
|||||||
*arg = pre.call(i)
|
*arg = pre.call(i)
|
||||||
message = "[#{i}]: in #{t}s #{info}"
|
message = "[#{i}]: in #{t}s #{info}"
|
||||||
Timeout.timeout(t, Timeout::Error, message) do
|
Timeout.timeout(t, Timeout::Error, message) do
|
||||||
st = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
measure[arg, message]
|
||||||
yield(*arg)
|
|
||||||
assert_operator (Process.clock_gettime(Process::CLOCK_MONOTONIC) - st), :<=, t, message unless rjit_enabled
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user