尝试使用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)
“用户”,“系统”和“真实”的含义是什么?
答案 0 :(得分:50)
这些与Unix time
命令或其他典型基准测试工具报告的次数相同:
答案 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