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