Module: ActiveSupport::Benchmark
- Defined in:
- lib/active_support/benchmark.rb
Overview
:nodoc:
Class Method Summary collapse
-
.realtime(unit = :float_second, &block) ⇒ Object
Benchmark realtime in the specified time unit.
Class Method Details
.realtime(unit = :float_second, &block) ⇒ Object
Benchmark realtime in the specified time unit. By default, the returned unit is in seconds.
ActiveSupport::Benchmark.realtime { sleep 0.1 }
# => 0.10007
ActiveSupport::Benchmark.realtime(:float_millisecond) { sleep 0.1 }
# => 100.07
‘unit` can be any of the values accepted by Ruby’s ‘Process.clock_gettime`.
15 16 17 18 19 |
# File 'lib/active_support/benchmark.rb', line 15 def self.realtime(unit = :float_second, &block) time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC, unit) yield Process.clock_gettime(Process::CLOCK_MONOTONIC, unit) - time_start end |