diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-03-12 18:50:39 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-03-12 18:50:39 +0900 |
commit | 7ce4b716bdb5bcfc8b30ffcd034ce7aded1f72b9 (patch) | |
tree | 500ecd184564fb4ae62ab6ff37e56d1fcadadb65 /tool | |
parent | 781222a8bc61597a72d6f64b15734a5fae38146a (diff) | |
download | ruby-7ce4b716bdb5bcfc8b30ffcd034ce7aded1f72b9.tar.gz |
Add test for linear performance
Diffstat (limited to 'tool')
-rw-r--r-- | tool/lib/core_assertions.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tool/lib/core_assertions.rb b/tool/lib/core_assertions.rb index 872402727a..12bff170b1 100644 --- a/tool/lib/core_assertions.rb +++ b/tool/lib/core_assertions.rb @@ -738,6 +738,29 @@ eom end alias all_assertions_foreach assert_all_assertions_foreach + def assert_linear_performance(factor: 10_000, first: factor, max: 2, pre: ->(n) {n}) + n = first + arg = pre.call(n) + tmax = (0..factor).map do + st = Process.clock_gettime(Process::CLOCK_MONOTONIC) + yield arg + (Process.clock_gettime(Process::CLOCK_MONOTONIC) - st) + end.max + + 1.upto(max) do |i| + i += 1 if first >= factor + 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 + end + def diff(exp, act) require 'pp' q = PP.new(+"") |