From: Eric Wong Date: 2014-08-23T21:44:06+00:00 Subject: [ruby-core:64515] Re: [ruby-trunk - Feature #10165] [Open] Use Process.clock_gettime to speed up Benchmark.realtime. I like this. The speedup is from reduction of allocations+GC I think you need to fall back to CLOCK_REALTIME on systems w/o CLOCK_MONOTONIC, though. Based on my reading of process.c, CLOCK_REALTIME is always available. So something like this: if defined?(Process::CLOCK_MONOTONIC) BENCHMARK_CLOCK = Process::CLOCK_MONOTONIC else # Ruby may use gettimeofday to emulate: BENCHMARK_CLOCK = Process::CLOCK_REALTIME end def realtime # :yield: r0 = Process.clock_gettime(BENCHMARK_CLOCK) yield Process.clock_gettime(BENCHMARK_CLOCK) - r0 end