Skip to content

Instantly share code, notes, and snippets.

@leoarnold
Last active June 21, 2021 09:17
Show Gist options
  • Save leoarnold/db986add1a2c51e871a2da3b8f129d23 to your computer and use it in GitHub Desktop.
Save leoarnold/db986add1a2c51e871a2da3b8f129d23 to your computer and use it in GitHub Desktop.
# @see https://blog.dnsimple.com/2018/03/elapsed-time-with-ruby-the-right-way/
def measure
started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
result = yield
ended_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
p ActiveSupport::Duration.build(ended_at - started_at)
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment