Sha256: 1f47b4c08e103cf43bbc44f14261c079184741bad6f0766ad363f6ba1acb3853

Contents?: true

Size: 556 Bytes

Versions: 6

Compression:

Stored size: 556 Bytes

Contents

# frozen_string_literal: true

class ImageOptim
  # Use Process.clock_gettime if available to get time more fitting to calculate elapsed time
  module ElapsedTime
    CLOCK_NAME = %w[
      CLOCK_UPTIME_RAW
      CLOCK_UPTIME
      CLOCK_MONOTONIC_RAW
      CLOCK_MONOTONIC
      CLOCK_REALTIME
    ].find{ |name| Process.const_defined?(name) }

    CLOCK_ID = CLOCK_NAME && Process.const_get(CLOCK_NAME)

  module_function

    def now
      if CLOCK_ID
        Process.clock_gettime(CLOCK_ID)
      else
        Time.now.to_f
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
image_optim-0.31.4 lib/image_optim/elapsed_time.rb
image_optim-0.31.3 lib/image_optim/elapsed_time.rb
image_optim-0.31.2 lib/image_optim/elapsed_time.rb
image_optim-0.31.1 lib/image_optim/elapsed_time.rb
image_optim-0.31.0 lib/image_optim/elapsed_time.rb
image_optim-0.30.0 lib/image_optim/elapsed_time.rb