Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
Benchmark.realtime
() { () -> void } -> ::Float
realtime() { || ... }
lib/benchmark.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/benchmark.rb, line 321
def realtime # :yield:
r0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield
Process.clock_gettime(Process::CLOCK_MONOTONIC) - r0
end
Returns the elapsed real time used to execute the given block. The unit of time is seconds.
Example
Benchmark.realtime { "a" * 1_000_000_000 } #=> 0.5098029999935534