Sha256: 5d61084f557e97c6d16bfb8a7ab7a1778a3d826d4be9d0f728a4f323325309b8

Contents?: true

Size: 686 Bytes

Versions: 11

Compression:

Stored size: 686 Bytes

Contents

# frozen_string_literal: true

module ActiveSupport
  module Benchmark # :nodoc:
    # 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`.
    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
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
activesupport-8.0.0 lib/active_support/benchmark.rb
activesupport-8.0.0.rc2 lib/active_support/benchmark.rb
activesupport-8.0.0.rc1 lib/active_support/benchmark.rb
activesupport-8.0.0.beta1 lib/active_support/benchmark.rb
omg-activesupport-8.0.0.alpha9 lib/active_support/benchmark.rb
omg-activesupport-8.0.0.alpha8 lib/active_support/benchmark.rb
omg-activesupport-8.0.0.alpha7 lib/active_support/benchmark.rb
omg-activesupport-8.0.0.alpha4 lib/active_support/benchmark.rb
omg-activesupport-8.0.0.alpha3 lib/active_support/benchmark.rb
omg-activesupport-8.0.0.alpha2 lib/active_support/benchmark.rb
omg-activesupport-8.0.0.alpha1 lib/active_support/benchmark.rb