Ruby Profiler


Advertisements


In most cases, you can improve the performance of a slow program by removing the bottleneck. The profiler is a tool that finds the bottleneck.

In order to add profiling to your Ruby program, you need to first load the Profile library using the command-line option -r profile.

Usage Syntax

$ ruby -r profile [programfile] [arguments]

Example

Here is the output generated from hello.rb file but this would not give you much idea so, you can try using a bigger program. Output is shown with small font.

[root@ruby]# ruby -r profile hello.rb
Hello, Mac!
   %   cumulative     self         self           total
   time    seconds  seconds      calls    ms/call  ms/call  name
   0.00     0.00      0.00        2       0.00     0.00    IO#write
   0.00     0.00      0.00        2       0.00     0.00    Module#method_added
   0.00     0.00      0.00        1       0.00     0.00    Hello#hello
   0.00     0.00      0.00        1       0.00     0.00    Hello#initialize
   0.00     0.00      0.00        1       0.00     0.00    Class#inherited
   0.00     0.00      0.00        1       0.00     0.00    Kernel.puts
   0.00     0.00      0.00        1       0.00     0.00    Class#new
   0.00     0.01      0.00        1       0.00    10.00    #toplevel

ruby_associated_tools.htm

Advertisements