Because measure accepts code blocks, you can make it as elaborate : Benchmark « Development « Ruby






Because measure accepts code blocks, you can make it as elaborate


require 'benchmark'
iterations = 1000000

b = Benchmark.measure do
  for i in 1..iterations do
    x = i
  end
end

c = Benchmark.measure do
  iterations.times do |i|
    x = i
  end
end

puts b
puts c

 








Related examples in the same category

1.Simple Benchmarking
2.Benchmark includes a way to make completing multiple tests more convenient.
3.Benchmark inline c
4.Benchmark reflection