1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/benchmark] Adds Tms#to_h

[Feature #17601]
This commit is contained in:
Keith Bennett 2021-02-07 23:02:52 -05:00 committed by Marc-Andre Lafortune
parent 9328112b9d
commit 3a7ff66abc
2 changed files with 23 additions and 0 deletions

View file

@ -527,6 +527,20 @@ module Benchmark
[@label, @utime, @stime, @cutime, @cstime, @real]
end
#
# Returns a hash containing the same data as `to_a`.
#
def to_h
{
label: @label,
utime: @utime,
stime: @stime,
cutime: @cutime,
cstime: @cstime,
real: @real
}
end
protected
#

View file

@ -155,4 +155,13 @@ BENCH
realtime = Benchmark.realtime { sleep sleeptime }
assert_operator sleeptime, :<, realtime
end
# Test that `to_h` returns a hash with the expected data.
def test_tms_to_h
tms = Benchmark::Tms.new(1.1, 2.2, 3.3, 4.4, 5.5, 'my label')
expected_hash = {
utime: 1.1, stime: 2.2, cutime: 3.3, cstime: 4.4, real: 5.5, label: 'my label'
}
assert_equal(expected_hash, tms.to_h)
end
end