End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
Benchmark::Tms#format
# File tmp/rubies/ruby-3.1.3/lib/benchmark.rb, line 504
def format(format = nil, *args)
str = (format || FORMAT).dup
str.gsub!(/(%[-+.\d]*)n/) { "#{$1}s" % label }
str.gsub!(/(%[-+.\d]*)u/) { "#{$1}f" % utime }
str.gsub!(/(%[-+.\d]*)y/) { "#{$1}f" % stime }
str.gsub!(/(%[-+.\d]*)U/) { "#{$1}f" % cutime }
str.gsub!(/(%[-+.\d]*)Y/) { "#{$1}f" % cstime }
str.gsub!(/(%[-+.\d]*)t/) { "#{$1}f" % total }
str.gsub!(/(%[-+.\d]*)r/) { "(#{$1}f)" % real }
format ? str % args : str
end
Returns the contents of this Tms object as a formatted string, according to a format string like that passed to Kernel.format. In addition, format accepts the following extensions:
%u-
Replaced by the user CPU time, as reported by
Tms#utime. %y-
Replaced by the system CPU time, as reported by
stime(Mnemonic: y of “s*y*stem”) %U-
Replaced by the children’s user CPU time, as reported by
Tms#cutime %Y-
Replaced by the children’s system CPU time, as reported by
Tms#cstime %t-
Replaced by the total CPU time, as reported by
Tms#total %r-
Replaced by the elapsed real time, as reported by
Tms#real %n-
Replaced by the label string, as reported by
Tms#label(Mnemonic: n of “*n*ame”)
If format is not given, FORMAT is used as default value, detailing the user, system and real elapsed time.