This uses the excellent benchmark-ips library by Evan Phoenix. You'll have to install that with:
gem install benchmark-ips
To do the Rails comparisons, you'll need to be within a Rails environment. The easiest thing would be to save the benchmark script into a Rails project, make sure benchmark-ips is in your Gemfile, and then enter a rails c environment. In the console, enter:
require_relative "01_benchmark"
This assumes you saved the benchmark in your Rails.root directory as 01_benchmark.rb.