O'Reilly logo

Ruby Performance Optimization by Alexander Dymo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required