class Benchmark::Tms
一个数据对象,表示与基准测试测量相关的时间。
常量
- CAPTION
默认标题,另请参阅 Benchmark::CAPTION
- FORMAT
默认格式字符串,另请参阅 Benchmark::FORMAT
属性
子进程的系统 CPU 时间
子进程的用户 CPU 时间
标签
经过的实际时间
系统 CPU 时间
总时间,即 utime + stime + cutime + cstime
用户 CPU 时间
公共类方法
返回一个初始化的 Tms 对象,它具有 utime 作为用户 CPU 时间,stime 作为系统 CPU 时间,cutime 作为子进程的用户 CPU 时间,cstime 作为子进程的系统 CPU 时间,real 作为经过的实际时间,以及 label 作为标签。
# File benchmark.rb, line 442 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
公共实例方法
根据传递给 Kernel.format 的类似 format 字符串,返回此 Tms 对象的内容作为格式化的字符串。此外,format 接受以下扩展
%u-
替换为用户 CPU 时间,如
Tms#utime报告的那样。 %y-
替换为系统 CPU 时间,如
stime报告的那样(助记符:*y* of “s*y*stem”) %U-
替换为子进程的用户 CPU 时间,如
Tms#cutime报告的那样 %Y-
替换为子进程的系统 CPU 时间,如
Tms#cstime报告的那样 %t-
替换为总 CPU 时间,如
Tms#total报告的那样 %r-
替换为经过的实际时间,如
Tms#real报告的那样 %n-
替换为标签字符串,如
Tms#label报告的那样(助记符:*n* of “*n*ame”)
如果未提供 format,则使用 FORMAT 作为默认值,详细说明用户、系统和经过的实际时间。
# File benchmark.rb, line 516 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
返回一个新的 6 元素数组,其中包含标签、用户 CPU 时间、系统 CPU 时间、子进程的用户 CPU 时间、子进程的系统 CPU 时间和经过的实际时间。
# File benchmark.rb, line 541 def to_a [@label, @utime, @stime, @cutime, @cstime, @real] end
返回一个包含与“to_a`相同数据的哈希。
# File benchmark.rb, line 548 def to_h { label: @label, utime: @utime, stime: @stime, cutime: @cutime, cstime: @cstime, real: @real } end
与 format 相同。
# File benchmark.rb, line 531 def to_s format end
受保护的实例方法
返回一个新的 Tms 对象,该对象是通过将此 Tms 对象的各个时间与另一个 Tms 对象 (x) 的各个时间进行按成员运算 op 得到的。
op 可以是数学运算,例如 +、-、*、/
# File benchmark.rb, line 569 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