Sha256: 04842af0644123e15638489455e6a2168c4aaa4b89efac86e142db1ecf830a6c

Contents?: true

Size: 1.03 KB

Versions: 22

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  # Handles timing of things
  #
  # @author Mikael Henriksson <mikael@mhenrixon.com>
  module Timing
    module_function

    #
    # Used for timing method calls
    #
    #
    # @return [yield return, Float]
    #
    def timed
      start_time = time_source.call

      [yield, time_source.call - start_time]
    end

    #
    # Used to get a current representation of time as Integer
    #
    #
    # @return [Integer]
    #
    def time_source
      -> { (clock_stamp * 1000).to_i }
    end

    #
    # Returns the current time as float
    #
    # @see SidekiqUniqueJobs.now_f
    #
    # @return [Float]
    #
    def now_f
      SidekiqUniqueJobs.now_f
    end

    #
    # Returns a float representation of the current time.
    #   Either from Process or Time
    #
    #
    # @return [Float]
    #
    def clock_stamp
      if Process.const_defined?("CLOCK_MONOTONIC")
        Process.clock_gettime(Process::CLOCK_MONOTONIC)
      else
        Time.now.to_f
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.0.13 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.1.3 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.1.2 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.1.1 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.1.0 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.12 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.11 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.10 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.9 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.8 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.7 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.6 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.5 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.4 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.3 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.2 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.1 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta29 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta28 lib/sidekiq_unique_jobs/timing.rb