Read more

Ruby: How to measure code execution time in an IRB or Rails console

Dominik Schöler
December 13, 2013Software engineer at makandra GmbH

Paste this method into your console:

def time(&block) puts Benchmark.measure(&block) end
Illustration book lover

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
Read more Show archive.org snapshot

Now time { Some.lengthy_task } will behave similar to the bash time command. Of course you can do much more with the Benchmark object than just putsing it – adapt to your needs.

Posted by Dominik Schöler to makandra dev (2013-12-13 16:58)