class Benchmark::Tms
A data object, representing the times associated with a benchmark measurement.
Constants
- CAPTION
-
Default caption, see also Benchmark::CAPTION
- FORMAT
-
Default format string, see also Benchmark::FORMAT
Attributes
System CPU time of children
User CPU time of children
Label
Elapsed real time
System CPU time
Total time, that is utime + stime + cutime + cstime
User CPU time
Public Class Methods
Source
# File bundled-src/benchmark-0.5.0/lib/benchmark.rb, line 456 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
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.
Public Instance Methods
Source
# File bundled-src/benchmark-0.5.0/lib/benchmark.rb, line 504 def *(x); memberwise(:*, x) end
Source
# File bundled-src/benchmark-0.5.0/lib/benchmark.rb, line 491 def +(other); memberwise(:+, other) end
Source
# File bundled-src/benchmark-0.5.0/lib/benchmark.rb, line 498 def -(other); memberwise(:-, other) end
Source
# File bundled-src/benchmark-0.5.0/lib/benchmark.rb, line 511 def /(x); memberwise(:/, x) end
Source
# File bundled-src/benchmark-0.5.0/lib/benchmark.rb, line 465 def add(&blk) # :yield: self + Benchmark.measure(&blk) end
Source
# File bundled-src/benchmark-0.5.0/lib/benchmark.rb, line 475 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
Source
# File bundled-src/benchmark-0.5.0/lib/benchmark.rb, line 530 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
Tms#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, total and real elapsed time.
Source
# File bundled-src/benchmark-0.5.0/lib/benchmark.rb, line 555 def to_a [@label, @utime, @stime, @cutime, @cstime, @real] end
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.
Source
# File bundled-src/benchmark-0.5.0/lib/benchmark.rb, line 562 def to_h { label: @label, utime: @utime, stime: @stime, cutime: @cutime, cstime: @cstime, real: @real } end
Returns a hash containing the same data as āto_a`.
Protected Instance Methods
Source
# File bundled-src/benchmark-0.5.0/lib/benchmark.rb, line 583 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