diff options
-rw-r--r-- | test/ruby/test_regexp.rb | 2 | ||||
-rw-r--r-- | tool/lib/core_assertions.rb | 39 |
2 files changed, 26 insertions, 15 deletions
@@ -1783,7 +1783,7 @@ class TestRegexp < Test::Unit::TestCase def test_linear_performance pre = ->(n) {[Regexp.new("a?" * n + "a" * n), "a" * n]} - assert_linear_performance(factor: 29, first: 10, max: 1, pre: pre) do |re, s| re =~ s end end @@ -738,23 +738,34 @@ eom end alias all_assertions_foreach assert_all_assertions_foreach - 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 - (Process.clock_gettime(Process::CLOCK_MONOTONIC) - st) - end.max - - (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 assert_operator (Process.clock_gettime(Process::CLOCK_MONOTONIC) - st), :<=, t, message end end |