Skip to content

Commit d97ca7d

Browse files
drolearyhsbt
authored andcommitted
Added a line to update @ToTal plus a test case for it
1 parent b9db5dd commit d97ca7d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/benchmark.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ def add!(&blk)
466466
@cutime = cutime + t.cutime
467467
@cstime = cstime + t.cstime
468468
@real = real + t.real
469+
@total = total + t.total
469470
self
470471
end
471472

test/benchmark/test_benchmark.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ def test_bugs_ruby_dev_40906_can_add_in_place_the_time_of_execution_of_the_block
150150
assert_not_equal(0, t.real)
151151
end
152152

153+
# TODO: Consider combining with the above test
154+
def test_add_in_place
155+
t = Benchmark::Tms.new
156+
assert_equal(0, t.total)
157+
158+
t.add! { 1000.times do ; '1'; end }
159+
assert_not_equal(0, t.total)
160+
end
161+
153162
def test_realtime_output
154163
sleeptime = 1.0
155164
realtime = Benchmark.realtime { sleep sleeptime }

0 commit comments

Comments
 (0)