Class | Benchmark::Tms |
In: |
benchmark.rb
|
Parent: | Object |
A data object, representing the times associated with a benchmark measurement.
CAPTION | = | " user system total real\n" |
FMTSTR | = | "%10.6u %10.6y %10.6t %10.6r\n" |
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 |
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 423 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
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 fmtstr is not given, FMTSTR is used as default value, detailing the user, system and real elapsed time.
# File benchmark.rb, line 494 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