Module: AbsoluteTime
- Defined in:
- ext/absolute_time.c,
ext/absolute_time.c
Overview
Ruby interface to monotonically-increasing system timer.
Class Method Summary collapse
-
.monotonic? ⇒ Boolean
Returns true if this module is able to use a guaranteed monotonically-increasing clock, false otherwise.
-
.now ⇒ Float
Returns the current value of the system timer as a floating-point number of seconds.
-
.realtime { ... } ⇒ Float
Like Benchmark.realtime(), returns the elapsed time to execute the specified block, as a floating-point number of seconds.
Class Method Details
.monotonic? ⇒ Boolean
Returns true if this module is able to use a guaranteed monotonically-increasing clock, false otherwise.
88 89 90 91 92 93 94 95 96 |
# File 'ext/absolute_time.c', line 88 static VALUE module_is_monotonic(VALUE self_) { #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) || defined(HAVE_MACH_MACH_TIME_H) return Qtrue; #else return Qfalse; #endif } |
.now ⇒ Float
Returns the current value of the system timer as a floating-point number of seconds. Although the units of the return value are seconds, they cannot be safely interpreted as a wall clock time. The return value is only useful when compared to the return value of a previous or subsequent call to AbsoluteTime.now().
If a monotonically increasing system clock is not available, this function falls back to using the wall clock time. You can check to see whether a monotonic clock is available using AbsoluteTime.monotonic?()
56 57 58 59 60 |
# File 'ext/absolute_time.c', line 56 static VALUE module_now(VALUE self_) { return rb_float_new(get_absolute_time()); } |
.realtime { ... } ⇒ Float
Like Benchmark.realtime(), returns the elapsed time to execute the specified block, as a floating-point number of seconds.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'ext/absolute_time.c', line 69 static VALUE module_realtime(VALUE self_) { double start_time, end_time; start_time = get_absolute_time(); rb_yield(Qnil); end_time = get_absolute_time(); return rb_float_new(end_time - start_time); } |