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

Visualize with Ruby-Prof Printers

Ruby-prof can generate several types of human-readable reports. I find three of them to be the most useful: flat, call graph, and call stack reports. (You can see the full list in the ruby-prof documentation.)[10] Each serves a different purpose. But we’re learning by example here, and to show them to you, I’ll need a more sophisticated example to profile.

chp4/app.rb
 
require ​'date'
 
require ​'rubygems'
 
require ​'ruby-prof'
 
 
# This generates CSV like
 
# 1, John McTest, 1980-07-01
 
# 2, Peter McGregor, 1985-12-23
 
# 3, Sylvia McIntosh, 1989-06-13
 
def​ generate_test_data
 
50000.times.map ​do​ |i|
 
name = [​"John"​, ​"Peter"​, ​"Sylvia"​][rand(3)] + ​" "​ +
 
[​"McTest"​, ​"McGregor"​, ​"McIntosh" ...

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