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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)