Skip to content

Commit d444574

Browse files
committed
Added a line to update @ToTal plus a test case for it
1 parent 8d2c8a0 commit d444574

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
@@ -455,6 +455,7 @@ def add!(&blk)
455455
@cutime = cutime + t.cutime
456456
@cstime = cstime + t.cstime
457457
@real = real + t.real
458+
@total = total + t.total
458459
self
459460
end
460461

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)