Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more
A data object, representing the times associated with a benchmark measurement.
Returns an initialized Tms object which has utime as the user CPU time, stime as the system CPU time, cutime as the children’s user CPU time, cstime as the children’s system CPU time, real as the elapsed real time and label as the label.
# File benchmark.rb, line 414
def initialize(utime = 0.0, stime = 0.0, cutime = 0.0, cstime = 0.0, real = 0.0, label = nil)
@utime, @stime, @cutime, @cstime, @real, @label = utime, stime, cutime, cstime, real, label.to_s
@total = @utime + @stime + @cutime + @cstime
end
An in-place version of add.
# File benchmark.rb, line 430
def add!(&blk)
t = Benchmark.measure(&blk)
@utime = utime + t.utime
@stime = stime + t.stime
@cutime = cutime + t.cutime
@cstime = cstime + t.cstime
@real = real + t.real
self
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 #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 #cutime
%Y
Replaced by the children’s system CPU time, as reported by #cstime
%t
Replaced by the total CPU time, as reported by #total
%r
Replaced by the elapsed real time, as reported by #real
%n
Replaced by the label string, as reported by #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.
# File benchmark.rb, line 485
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 a new Tms object obtained by memberwise
operation op of the individual times for this Tms object with those of the other Tms object.
op can be a mathematical operation such as +,
-, *, /
# File benchmark.rb, line 524
def memberwise(op, x)
case x
when Benchmark::Tms
Benchmark::Tms.new(utime.__send__(op, x.utime),
stime.__send__(op, x.stime),
cutime.__send__(op, x.cutime),
cstime.__send__(op, x.cstime),
real.__send__(op, x.real)
)
else
Benchmark::Tms.new(utime.__send__(op, x),
stime.__send__(op, x),
cutime.__send__(op, x),
cstime.__send__(op, x),
real.__send__(op, x)
)
end
end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.