Get Off My Lawn

Adventures of a Curmudgeon

NTS: Benchmark.measure

1
2
3
4
5
$> script/console
>> require 'benchmark'
>> result = Benchmark.measure { [your stuff here] }
>> puts result
>> xxx / 60

Divide the last number printed (the one in the parentheses) to get a rough idea of how many minutes the operation took.

I’ve had to, on a couple of occasions, fire of script/console in production and massage some data, basically apply some business logic on some Models. Sometimes this process can take a while, so, in order to provide some idea of the length of execution I can now execute this in my development environment and the staging environment.

You can also use this in scripts that you may use with script/runner.

Cheers!