接上篇: List performance: ruby 1.8 and 1.9 (Part 1)
有了之前的准备和热身,真正跑起步来似乎轻松不少,先贴上我们用来benchmark的code:
require 'benchmark'
n = ARGV.empty? ? 10 ** 6 : 10 ** ARGV[0].to_i
puts "n=#{n}"
Benchmark.bmbm do |x|
x.report do
list = []
n.times do
list < < 0
end
end
end
n = ARGV.empty? ? 10 ** 6 : 10 ** ARGV[0].to_i
puts "n=#{n}"
Benchmark.bmbm do |x|
x.report do
list = []
n.times do
list < < 0
end
end
end
和之前用来benchmark loop performance的code结构上基本没有区别,这里不再赘述,具体的解释亦可参照前文。
Continue reading →
on
on
on
on
on