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

Updated . Posted . Visible to the public.

Paste this method into your console:

def time(&block) puts Benchmark.measure(&block) end

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.

Dominik Schöler
Last edit
Dominik Schöler
Keywords
Ruby
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2013-12-13 15:58)