Class Benchmark::Tms
In: lib/benchmark.rb
Parent: Object

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

Methods

*   +   -   /   add   add!   format   memberwise   new   to_a   to_s  

Constants

CAPTION = " user system total real\n"
FMTSTR = "%10.6u %10.6y %10.6t %10.6r\n"

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

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.

[Source]

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

Public Instance methods

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

[Source]

     # File lib/benchmark.rb, line 471
471:     def *(x); memberwise(:*, x) end

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.

[Source]

     # File lib/benchmark.rb, line 458
458:     def +(other); memberwise(:+, other) end

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

[Source]

     # File lib/benchmark.rb, line 465
465:     def -(other); memberwise(:-, other) end

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.

[Source]

     # File lib/benchmark.rb, line 478
478:     def /(x); memberwise(:/, x) end

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).

[Source]

     # File lib/benchmark.rb, line 435
435:     def add(&blk) # :yield:
436:       self + Benchmark::measure(&blk) 
437:     end

An in-place version of add.

[Source]

     # File lib/benchmark.rb, line 442
442:     def add!
443:       t = Benchmark::measure(&blk) 
444:       @utime  = utime + t.utime
445:       @stime  = stime + t.stime
446:       @cutime = cutime + t.cutime
447:       @cstime = cstime + t.cstime
448:       @real   = real + t.real
449:       self
450:     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.

[Source]

     # File lib/benchmark.rb, line 497
497:     def format(arg0 = nil, *args)
498:       fmtstr = (arg0 || FMTSTR).dup
499:       fmtstr.gsub!(/(%[-+\.\d]*)n/){"#{$1}s" % label}
500:       fmtstr.gsub!(/(%[-+\.\d]*)u/){"#{$1}f" % utime}
501:       fmtstr.gsub!(/(%[-+\.\d]*)y/){"#{$1}f" % stime}
502:       fmtstr.gsub!(/(%[-+\.\d]*)U/){"#{$1}f" % cutime}
503:       fmtstr.gsub!(/(%[-+\.\d]*)Y/){"#{$1}f" % cstime}
504:       fmtstr.gsub!(/(%[-+\.\d]*)t/){"#{$1}f" % total}
505:       fmtstr.gsub!(/(%[-+\.\d]*)r/){"(#{$1}f)" % real}
506:       arg0 ? Kernel::format(fmtstr, *args) : fmtstr
507:     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 lib/benchmark.rb, line 522
522:     def to_a
523:       [@label, @utime, @stime, @cutime, @cstime, @real]
524:     end

Same as format.

[Source]

     # File lib/benchmark.rb, line 512
512:     def to_s
513:       format
514:     end

Protected Instance methods

[Source]

     # File lib/benchmark.rb, line 527
527:     def memberwise(op, x)
528:       case x
529:       when Benchmark::Tms
530:         Benchmark::Tms.new(utime.__send__(op, x.utime),
531:                            stime.__send__(op, x.stime),
532:                            cutime.__send__(op, x.cutime),
533:                            cstime.__send__(op, x.cstime),
534:                            real.__send__(op, x.real)
535:                            )
536:       else
537:         Benchmark::Tms.new(utime.__send__(op, x),
538:                            stime.__send__(op, x),
539:                            cutime.__send__(op, x),
540:                            cstime.__send__(op, x),
541:                            real.__send__(op, x)
542:                            )
543:       end
544:     end

[Validate]