Ruby Benchmark module:quot;用户"&引用;系统";,及;真的;?

Ruby Benchmark module:quot;用户"&引用;系统";,及;真的;?,ruby,performance,benchmarking,Ruby,Performance,Benchmarking,正在试验Ruby的基准测试模块 >> Benchmark.bm(7) { |b| b.report('Report:') { s = '' ; 10000.times { s += 'a' } } } user system total real Report: 0.150000 0.010000 0.160000 ( 0.156361) “用户”、“系统”和“真实”的含义是什么?这与Unixtime命令或其他

正在试验Ruby的基准测试模块

>> Benchmark.bm(7) { |b| b.report('Report:') { s = '' ; 10000.times { s += 'a' } }  }
             user     system      total        real
Report:  0.150000   0.010000   0.160000 (  0.156361)

“用户”、“系统”和“真实”的含义是什么?

这与Unix
time
命令或其他典型基准测试工具报告的时间相同:

  • 用户:执行用户空间代码(即:您的代码)所花费的时间量
  • 系统:执行内核代码和
  • 实际:执行代码所花费的“实际”时间量(即系统+用户+等待i/O、网络、磁盘、用户输入等所花费的时间)。也称为“挂钟时间”
请检查此宝石:

不再有这样的代码:

t = Time.now
user.calculate_report
puts Time.now - t
现在您可以执行以下操作:

benchmark :calculate_report # in class
然后调用你的方法

user.calculate_report

@jorg基准测试的Ruby文档是否错误,因为它们显示的实时时间比总时间短得多?来源:@rscott:user、system和total指的是所有内核的时间总和,而real只是字面上的总时间。因此,如果代码在多核系统上运行,前三个中的任何一个都可能超过后一个。那么“总数”呢?我有一个基准,“总计”超过“用户”+“系统”之和。怎么可能呢?