From 09041a6ee8aadf8d87cc57d8546f134861bbcb8f Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 15 Mar 2023 18:19:31 +0900 Subject: [PATCH] core_assertions.rb: Refine `assert_linear_performance` * Add `rehearsal` keyword argument * Stop repeating with the same factor --- tool/lib/core_assertions.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tool/lib/core_assertions.rb b/tool/lib/core_assertions.rb index 12bff170b1..119deccb9f 100644 --- a/tool/lib/core_assertions.rb +++ b/tool/lib/core_assertions.rb @@ -738,17 +738,16 @@ eom end alias all_assertions_foreach assert_all_assertions_foreach - def assert_linear_performance(factor: 10_000, first: factor, max: 2, pre: ->(n) {n}) + def assert_linear_performance(factor: 10_000, first: factor, max: 2, rehearsal: first, pre: ->(n) {n}) n = first arg = pre.call(n) - tmax = (0..factor).map do + tmax = (0..rehearsal).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 + (first >= factor ? 2 : 1).upto(max) do |i| n = i * factor t = tmax * factor arg = pre.call(n)