Sha256: 5b61ba7833f698b484d474052a025dbe8e47dc96378d5f35b8cee19b6e4475be

Contents?: true

Size: 1.03 KB

Versions: 24

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  # Handles timing of things
  #
  # @author Mikael Henriksson <mikael@zoolutions.se>
  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

24 entries across 24 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.0.0.beta25 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta24 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta23 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta22 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta21 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta20 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta19 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta18 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta17 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta16 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta15 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta14 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta13 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta12 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta11 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta10 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta9 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta8 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta7 lib/sidekiq_unique_jobs/timing.rb
sidekiq-unique-jobs-7.0.0.beta6 lib/sidekiq_unique_jobs/timing.rb