Module: ImageOptim::ElapsedTime

Included in:
Timer
Defined in:
lib/image_optim/elapsed_time.rb

Overview

Use Process.clock_gettime if available to get time more fitting to calculate elapsed time

Constant Summary collapse

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)

Class Method Summary collapse

Class Method Details

.nowObject



18
19
20
21
22
23
24
# File 'lib/image_optim/elapsed_time.rb', line 18

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