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)
benchmark
最新推荐文章于 2024-03-02 20:03:22 发布