Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

Process.clock_getres

(::Symbol | ::Integer clock_id, ?::Symbol unit) -> (::Float | ::Integer)
Process.clock_getres(clock_id, unit = :float_second) → number

Returns a clock resolution as determined by POSIX function clock_getres():

Example
Process.clock_getres(:CLOCK_REALTIME) # => 1.0e-09

See Process.clock_gettime for the values of clock_id and unit.

Examples:

Example
Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :float_microsecond) # => 0.001
Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :float_millisecond) # => 1.0e-06
Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :float_second)      # => 1.0e-09
Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :microsecond)       # => 0
Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :millisecond)       # => 0
Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :nanosecond)        # => 1
Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :second)            # => 0

In addition to the values for unit supported in Process.clock_gettime, this method supports :hertz, the integer number of clock ticks per second (which is the reciprocal of :float_second):

Example
Process.clock_getres(:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz)        # => 100.0
Process.clock_getres(:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :float_second) # => 0.01

Accuracy: Note that the returned resolution may be inaccurate on some platforms due to underlying bugs. Inaccurate resolutions have been reported for various clocks including :CLOCK_MONOTONIC and :CLOCK_MONOTONIC_RAW on Linux, macOS, BSD or AIX platforms, when using ARM processors, or when using virtualization.

See also .argv0 .clock_gettime .abort .daemon also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0