class Benchmark::Tms


measurement.
A data object, representing the times associated with a benchmark

def *(x); memberwise(:*, x) end


of the individual times for this Tms object by +x+.
Returns a new Tms object obtained by memberwise multiplication
def *(x); memberwise(:*, x) end

def +(other); memberwise(:+, other) end


This method and #/() are useful for taking statistics.
Tms object.
of the individual times for this Tms object with those of the +other+
Returns a new Tms object obtained by memberwise summation
def +(other); memberwise(:+, other) end

def -(other); memberwise(:-, other) end


Tms object.
of the individual times for the +other+ Tms object from those of this
Returns a new Tms object obtained by memberwise subtraction
def -(other); memberwise(:-, other) end

def /(x); memberwise(:/, x) end


This method and #+() are useful for taking statistics.
of the individual times for this Tms object by +x+.
Returns a new Tms object obtained by memberwise division
def /(x); memberwise(:/, x) end

def add(&blk) # :yield:

:yield:

Tms object, plus the time required to execute the code block (+blk+).
Returns a new Tms object whose times are the sum of the times for this
def add(&blk) # :yield:
  self + Benchmark.measure(&blk)
end

def add!(&blk)


the code block (+blk+).
for this Tms object, plus the time required to execute
Changes the times of this Tms object by making it the sum of the times
An in-place version of #add.
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

def format(format = nil, *args)


user, system and real elapsed time.
If +format+ is not given, FORMAT is used as default value, detailing the

%n:: Replaced by the label string, as reported by Tms#label (Mnemonic: n of "*n*ame")
%r:: Replaced by the elapsed real time, as reported by Tms#real
%t:: Replaced by the total CPU time, as reported by Tms#total
%Y:: Replaced by the children's system CPU time, as reported by Tms#cstime
%U:: Replaced by the children's user CPU time, as reported by Tms#cutime
%y:: Replaced by the system CPU time, as reported by #stime (Mnemonic: y of "s*y*stem")
%u:: Replaced by the user CPU time, as reported by Tms#utime.

accepts the following extensions:
like that passed to Kernel.format. In addition, #format
a formatted string, according to a +format+ string
Returns the contents of this Tms object as
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

def initialize(utime = 0.0, stime = 0.0, cutime = 0.0, cstime = 0.0, real = 0.0, label = nil)


system CPU time, +real+ as the elapsed real time and +label+ as the label.
+cutime+ as the children's user CPU time, +cstime+ as the children's
+utime+ as the user CPU time, +stime+ as the system CPU time,
Returns an initialized Tms object which has
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

def memberwise(op, x)


*, /
+op+ can be a mathematical operation such as +, -,

Tms object (+x+).
of the individual times for this Tms object with those of the other
Returns a new Tms object obtained by memberwise operation +op+
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

def to_a


real time.
user CPU time, children's system CPU time and elapsed
label, user CPU time, system CPU time, children's
Returns a new 6-element array, consisting of the
def to_a
  [@label, @utime, @stime, @cutime, @cstime, @real]
end

def to_h


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

def to_s


Same as #format.
def to_s
  format
end