mirror of
https://github.com/ruby/ruby.git
synced 2025-09-16 17:14:01 +02:00
core_assertions.rb: Extract common code block
This commit is contained in:
parent
d86deaf383
commit
7bb789bf99
1 changed files with 9 additions and 8 deletions
|
@ -734,15 +734,18 @@ eom
|
|||
def assert_linear_performance(seq, rehearsal: nil, pre: ->(n) {n})
|
||||
# Timeout testing generally doesn't work when RJIT compilation happens.
|
||||
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
|
||||
*arg = pre.call(first)
|
||||
times = (0..(rehearsal || (2 * first))).map do
|
||||
st = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||
yield(*arg)
|
||||
t = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - st)
|
||||
assert_operator 0, :<=, t unless rjit_enabled
|
||||
t.nonzero?
|
||||
measure[arg, "rehearsal"].nonzero?
|
||||
end
|
||||
times.compact!
|
||||
tmin, tmax = times.minmax
|
||||
|
@ -755,9 +758,7 @@ eom
|
|||
*arg = pre.call(i)
|
||||
message = "[#{i}]: in #{t}s #{info}"
|
||||
Timeout.timeout(t, Timeout::Error, message) do
|
||||
st = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||
yield(*arg)
|
||||
assert_operator (Process.clock_gettime(Process::CLOCK_MONOTONIC) - st), :<=, t, message unless rjit_enabled
|
||||
measure[arg, message]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue