Measure with Ruby-Prof

ruby-prof is a Ruby gem that comes with both an API and a command-line tool. In most cases you’ll probably want use the API to profile just that isolated part of the code that you suspect to be slow. But the command-line tool is what you want for profiling application startup, especially if you’re interested in rubygems startup costs. In Rails applications you can get the complete request profile by inserting ruby-prof into the middleware stack.

1. ruby-prof API

In this example we’ll use the ruby-prof API to profile a specific part of your code.

chp4/ruby_prof_example_api1.rb
 
require ​'date'
 
require ​'rubygems'
 
require ​'ruby-prof'
 
 
GC.disable
 
 
RubyProf.start
 
Date.parse(​"2014-07-01"​)
 
result = RubyProf.stop ...

Get Ruby Performance Optimization now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.