Benchmarking in the Rails Console

Public, Ruby General, Rails Errors


Created: Dec 22, 2017     Updated: Jun 16, 2020

timing = Benchmark.measure { Post.all }

The various attributes of the object returned (Benchmark::Tms) are provided here.

Here is a sample application of this in the rails console:

[10] pry(main)> Benchmark.measure { Directory::CountyZipcode.pluck(:state).uniq.sort }
  [read] (24.0ms)  SELECT `county_zipcodes`.`state` FROM `county_zipcodes`
=> #<Benchmark::Tms:0x007fa731d4e8a8

[11] pry(main)> Benchmark.measure { }
  [read] Directory::CountyZipcode Load (35.3ms)  SELECT DISTINCT `county_zipcodes`.`state` FROM `county_zipcodes` ORDER BY `county_zipcodes`.`state` ASC
=> #<Benchmark::Tms:0x007fa7372831c0