Benchmark includes a way to make completing multiple tests more convenient. : Benchmark « Development « Ruby






Benchmark includes a way to make completing multiple tests more convenient.


require 'benchmark'
iterations = 1000000

Benchmark.bm do |bm|
  bm.report("for:") do
    for i in 1..iterations do
      x = i
    end
  end
  bm.report("times:") do
    iterations.times do |i|
      x = i
    end
  end
end

 








Related examples in the same category

1.Simple Benchmarking
2.Because measure accepts code blocks, you can make it as elaborate
3.Benchmark inline c
4.Benchmark reflection