summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-04-03 14:22:24 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-04-06 00:19:03 +0900
commitf9eb2515a3221cced611b4de971b72a78a7a566f (patch)
tree474486f1a6bc5054da0baef43614d9142d9d5899 /tool
parentf07c756494b0e473ff8e4ece6f04c7ababe93b01 (diff)
downloadruby-f9eb2515a3221cced611b4de971b72a78a7a566f.tar.gz
core_assertions.rb: Extract common code block
Diffstat (limited to 'tool')
-rw-r--r--tool/lib/core_assertions.rb17
1 files changed, 9 insertions, 8 deletions
diff --git a/tool/lib/core_assertions.rb b/tool/lib/core_assertions.rb
index 6000d39c90..81faac1e4b 100644
--- a/tool/lib/core_assertions.rb
+++ b/tool/lib/core_assertions.rb
@@ -746,15 +746,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
@@ -767,9 +770,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