Skip to content

Instantly share code, notes, and snippets.

@meagar
meagar / benchmark.rb
Created December 1, 2020 15:00
Monotonic time for benchmarking
# Source: https://blog.dnsimple.com/2018/03/elapsed-time-with-ruby-the-right-way/
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
# time consuming operation
ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
elapsed = ending - starting
elapsed # => 9.183449000120163 seconds