In Files

  • benchmark.rb

Class/Module Index [+]

Quicksearch

Benchmark::Tms

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

Constants

CAPTION
FMTSTR

Attributes

cstime[R]

System CPU time of children

cutime[R]

User CPU time of children

label[R]

Label

real[R]

Elapsed real time

stime[R]

System CPU time

total[R]

Total time, that is utime + stime + cutime + cstime

utime[R]

User CPU time

Public Class Methods

new(u = 0.0, s = 0.0, cu = 0.0, cs = 0.0, real = 0.0, l = nil) click to toggle source

Returns an initialized Tms object which has u as the user CPU time, s as the system CPU time, cu as the children's user CPU time, cs as the children's system CPU time, real as the elapsed real time and l as the label.

 
               # File benchmark.rb, line 428
def initialize(u = 0.0, s = 0.0, cu = 0.0, cs = 0.0, real = 0.0, l = nil)
  @utime, @stime, @cutime, @cstime, @real, @label = u, s, cu, cs, real, l
  @total = @utime + @stime + @cutime + @cstime
end
            

Public Instance Methods

*(x) click to toggle source

Returns a new Tms object obtained by memberwise multiplication of the individual times for this Tms object by x.

 
               # File benchmark.rb, line 473
def *(x); memberwise(:*, x) end
            
+(other) click to toggle source

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

 
               # File benchmark.rb, line 460
def +(other); memberwise(:+, other) end
            
-(other) click to toggle source

Returns a new Tms object obtained by memberwise subtraction of the individual times for the other Tms object from those of this Tms object.

 
               # File benchmark.rb, line 467
def -(other); memberwise(:-, other) end
            
/(x) click to toggle source

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

 
               # File benchmark.rb, line 480
def /(x); memberwise(:/, x) end
            
add() click to toggle source

Returns a new Tms object whose times are the sum of the times for this Tms object, plus the time required to execute the code block (blk).

 
               # File benchmark.rb, line 437
def add(&blk) # :yield:
  self + Benchmark::measure(&blk)
end
            
add!(&blk) click to toggle source

An in-place version of add.

 
               # File benchmark.rb, line 444
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
            
format(arg0 = nil, *args) click to toggle source

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 fmtstr is not given, FMTSTR is used as default value, detailing the user, system and real elapsed time.

 
               # File benchmark.rb, line 499
def format(arg0 = nil, *args)
  fmtstr = (arg0 || FMTSTR).dup
  fmtstr.gsub!(/(%[-+\.\d]*)n/){"#{$1}s" % label}
  fmtstr.gsub!(/(%[-+\.\d]*)u/){"#{$1}f" % utime}
  fmtstr.gsub!(/(%[-+\.\d]*)y/){"#{$1}f" % stime}
  fmtstr.gsub!(/(%[-+\.\d]*)U/){"#{$1}f" % cutime}
  fmtstr.gsub!(/(%[-+\.\d]*)Y/){"#{$1}f" % cstime}
  fmtstr.gsub!(/(%[-+\.\d]*)t/){"#{$1}f" % total}
  fmtstr.gsub!(/(%[-+\.\d]*)r/){"(#{$1}f)" % real}
  arg0 ? Kernel::format(fmtstr, *args) : fmtstr
end
            
to_a() click to toggle source

Returns a new 6-element array, consisting of the label, user CPU time, system CPU time, children's user CPU time, children's system CPU time and elapsed real time.

 
               # File benchmark.rb, line 524
def to_a
  [@label, @utime, @stime, @cutime, @cstime, @real]
end
            
to_s() click to toggle source

Same as format.

 
               # File benchmark.rb, line 514
def to_s
  format
end
            

Protected Instance Methods

memberwise(op, x) click to toggle source
 
               # File benchmark.rb, line 529
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