How to benchmark your Ruby code

Tagged benchmark, performance, ruby  Languages ruby

You can easily benchmark your Ruby code like this:

require 'benchmark'
seconds = Benchmark.realtime do
    sleep 1
end
print "#{seconds} elapsed..."

The output should be close to 1 second.