a = (1..10000).to_a
Benchmark.bm(30) do |x|
  x.report("random a 10000 element array 100 times") do
    100.times { a.sort_by { rand } }
  end
end
Benchmark.bm(30) do |x|
  x.report("shuffle a 10000 element array 100 times") do
    100.times { a.shuffle }
  end
end
输出结果:
                                           user      system     total      real
random a 10000 element array 100 times  1.600000   0.000000   1.600000 (  1.602049)
                                          user       system     total      real
shuffle a 10000 element array 100 times  0.030000   0.010000   0.040000 (  0.041415)