Occasionally I read Rails source code to learn/re-learn what it’s capable of.
Want to do some quick and dirty profiling to see how long some Ruby code takes? Do this in irb or in a Ruby project:
require 'rubygems' require 'active_support/core_ext/benchmark' puts Benchmark.ms do # put your code here end
The output is how long in milliseconds the code took to run.
This requires ActiveSupport but does not require all of Rails. If you don’t have ActiveSupport, install it with gem install activesupport.