diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-04-03 14:22:24 +0900 |
|---|---|---|
| committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2024-09-10 16:00:29 +0900 |
| commit | 7bb789bf99dfd9b44f92287bf93893e76d1bac28 (patch) | |
| tree | 4aeefc93d00125c12a637785cbbace25fabbfbfd /tool | |
| parent | d86deaf3832a9cb4686a2f9bf540033d3546f4c7 (diff) | |
core_assertions.rb: Extract common code block
Diffstat (limited to 'tool')
| -rw-r--r-- | tool/lib/core_assertions.rb | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/tool/lib/core_assertions.rb b/tool/lib/core_assertions.rb index f4c096adf8..8761780cfb 100644 --- a/tool/lib/core_assertions.rb +++ b/tool/lib/core_assertions.rb @@ -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 |
