benchmark

来源:互联网 发布:2017年病退工资的算法 编辑:程序博客网 时间:2024/05/18 03:59
require 'benchmark'
n = 1000000
Benchmark.bm do |x|
x.report {
for i in 1..n;
a = "1";
end
}
x.report {
n.times do;
a = "1";
end
}
x.report {
1.upto(n) do;
a = "1";
end
}
end
# user system total real
# 0.480000 0.000000 0.480000 ( 0.481000)
# 0.571000 0.000000 0.571000 ( 0.581000)
# 0.581000 0.000000 0.581000 ( 0.581000)
 
原创粉丝点击