Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Benchmark.measure

measure(label = "") { || ... }

Returns the time used to execute the given block as a Benchmark::Tms object. Takes label option.

Example
require 'benchmark'

n = 1000000

time = Benchmark.measure do
  n.times { a = "1" }
end
puts time

Generates:

0.220000   0.000000   0.220000 (  0.227313)
See also #measure .bmbm .realtime .bm also in 3.4 · 3.3 · 3.1 · 3.0