试验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)
“用户”,“系统”和“真实”的含义是什么?
这些是Unix time 命令或其他典型基准测试工具报告的相同时间:
time
user:执行用户空间代码所花费的时间(即:您的代码),
system:执行内核代码所花费的时间和
real:"real"执行代码所花费的时间(即等待I / O,网络,磁盘,用户输入等所花费的系统用户时间) . 又称"wallclock time" .
请检查这个宝石:https://github.com/igorkasyanchuk/benchmark_methods
没有这样的代码:
t = Time.now user.calculate_report puts Time.now - t
现在你可以这样做:
benchmark :calculate_report # in class
然后打电话给你的方法
user.calculate_report
2 回答
这些是Unix
time
命令或其他典型基准测试工具报告的相同时间:user:执行用户空间代码所花费的时间(即:您的代码),
system:执行内核代码所花费的时间和
real:"real"执行代码所花费的时间(即等待I / O,网络,磁盘,用户输入等所花费的系统用户时间) . 又称"wallclock time" .
请检查这个宝石:https://github.com/igorkasyanchuk/benchmark_methods
没有这样的代码:
现在你可以这样做:
然后打电话给你的方法