Skip to content

Commit

Permalink
Revert "core_assertions.rb: Refine assert_linear_performance"
Browse files Browse the repository at this point in the history
This reverts commit cae4342.

This is failing a lot of CIs and nobody is actively looking into fixing
it. Let me revert this until we have a solution to it.
  • Loading branch information
k0kubun committed Mar 16, 2023
1 parent 2f81bb7 commit a8e7fee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion test/ruby/test_regexp.rb
Expand Up @@ -1783,7 +1783,7 @@ def test_linear_time_p

def test_linear_performance
pre = ->(n) {[Regexp.new("a?" * n + "a" * n), "a" * n]}
assert_linear_performance([10, 29], pre: pre) do |re, s|
assert_linear_performance(factor: 29, first: 10, max: 1, pre: pre) do |re, s|
re =~ s
end
end
Expand Down
27 changes: 11 additions & 16 deletions tool/lib/core_assertions.rb
Expand Up @@ -738,28 +738,23 @@ def assert_all_assertions_foreach(msg = nil, *keys, &block)
end
alias all_assertions_foreach assert_all_assertions_foreach

# Expect +seq+ to respond to +first+ and +each+ methods, e.g.,
# Array, Range, Enumerator::ArithmeticSequence and other
# Enumerable-s, and each elements should be size factors.
#
# :yield: each elements of +seq+.
def assert_linear_performance(seq, rehearsal: nil, pre: ->(n) {n})
first = seq.first
*arg = pre.call(first)
tmax = (0..(rehearsal || first)).map do
def assert_linear_performance(factor: 10_000, first: factor, max: 2, rehearsal: first, pre: ->(n) {n})
n = first
arg = pre.call(n)
tmax = (0..rehearsal).map do
st = Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield(*arg)
yield arg
(Process.clock_gettime(Process::CLOCK_MONOTONIC) - st)
end.max

seq.each do |i|
next if i == first
t = tmax * i / first
*arg = pre.call(i)
message = "[#{i}]: in #{t}s"
(first >= factor ? 2 : 1).upto(max) do |i|
n = i * factor
t = tmax * factor
arg = pre.call(n)
message = "[#{i}]: #{n} in #{t}s"
Timeout.timeout(t, nil, message) do
st = Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield(*arg)
yield arg
assert_operator (Process.clock_gettime(Process::CLOCK_MONOTONIC) - st), :<=, t, message
end
end
Expand Down

0 comments on commit a8e7fee

Please sign in to comment.