[ruby/benchmark] Adds `Tms#to_h`

[Feature #17601]
This commit is contained in:
Keith Bennett 2021-02-07 23:02:52 -05:00 коммит произвёл Marc-Andre Lafortune
Родитель 9328112b9d
Коммит 3a7ff66abc
2 изменённых файлов: 23 добавлений и 0 удалений

Просмотреть файл

@ -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
#

Просмотреть файл

@ -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