Ruby Benchmark模块:“用户”,“系统”和“真实”的含义?

时间:2009-10-23 22:33:44

标签: ruby performance benchmarking

尝试使用Ruby的Benchmark模块...

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

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

2 个答案:

答案 0 :(得分:50)

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

  • 用户:执行用户空间代码所花费的时间(即:您的代码),
  • system :执行内核代码所花费的时间和
  • 真实:执行代码所需的“实际”时间(即系统 + 用户 +等待我的时间/ O,网络,磁盘,用户输入等)。也被称为“挂钟时间”。

答案 1 :(得分:-5)

请检查此宝石: https://github.com/igorkasyanchuk/benchmark_methods

不再有这样的代码:

t = Time.now
user.calculate_report
puts Time.now - t

现在你可以做到:

benchmark :calculate_report # in class

然后调用你的方法

user.calculate_report