From d97ca7dfc5935899ff33db22a7b27adb9463a12a Mon Sep 17 00:00:00 2001 From: Doc O'Leary Date: Thu, 20 Jun 2024 12:58:42 -0500 Subject: [PATCH] Added a line to update @total plus a test case for it --- lib/benchmark.rb | 1 + test/benchmark/test_benchmark.rb | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/benchmark.rb b/lib/benchmark.rb index 8eef744..e43106b 100644 --- a/lib/benchmark.rb +++ b/lib/benchmark.rb @@ -466,6 +466,7 @@ def add!(&blk) @cutime = cutime + t.cutime @cstime = cstime + t.cstime @real = real + t.real + @total = total + t.total self end diff --git a/test/benchmark/test_benchmark.rb b/test/benchmark/test_benchmark.rb index 2e0c47a..5caef87 100644 --- a/test/benchmark/test_benchmark.rb +++ b/test/benchmark/test_benchmark.rb @@ -150,6 +150,15 @@ def test_bugs_ruby_dev_40906_can_add_in_place_the_time_of_execution_of_the_block assert_not_equal(0, t.real) end + # TODO: Consider combining with the above test + def test_add_in_place + t = Benchmark::Tms.new + assert_equal(0, t.total) + + t.add! { 1000.times do ; '1'; end } + assert_not_equal(0, t.total) + end + def test_realtime_output sleeptime = 1.0 realtime = Benchmark.realtime { sleep sleeptime }