Ruby-profiler

提供:Dev Guides
移動先:案内検索

Rubyプロファイラー

ほとんどの場合、ボトルネックを取り除くことにより、低速プログラムのパフォーマンスを改善できます。 プロファイラーは、ボトルネックを見つけるツールです。

Rubyプログラムにプロファイリングを追加するには、最初にコマンドラインオプション_-r profile_を使用して_Profile_ライブラリをロードする必要があります。

使用構文

$ ruby -r profile [programfile] [arguments]

_hello.rb_ファイルから生成された出力を次に示しますが、これはあまりわかりませんので、より大きなプログラムを使用してみてください。 出力は小さなフォントで表示されます。

[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