カテゴリ: Ruby
Rubyコマンドでプロファイルを取得
Rubyを勉強していて知った事の私的メモ。
最近Rubyの本読んでいて知ったTips
Rubyコマンドに "-r profile"オプション渡してプログラム実行すると、各メソッドのコール回数や実行時間のプロファイリングが出来るんですね。
てな具合に。 丁度良い実験体が無かったので、Railsのtest_helper.rb使いました。 実際はもっと長く出力されるので、一端ファイルに落とそうとリダイレクトしてみたんですが、 コレ標準出力では無くて、標準エラー出力に出されるんですねぇ。一度誤爆しました。$ ruby -r profile test_helper.rb % cumulative self self total time seconds seconds calls ms/call ms/call name 22.00 1.91 1.91 697 2.74 44.16 Kernel.require__ 17.28 3.41 1.50 6426 0.23 0.28 Object#method_added 7.37 4.05 0.64 576 1.11 27.53 Array#each 2.65 4.28 0.23 6435 0.04 0.04 Module#blank_slate_method_added 2.30 4.48 0.20 730 0.27 63.27 Kernel.require 1.73 4.63 0.15 966 0.16 0.37 Class#inherited 1.61 4.77 0.14 1 140.00 160.00 ObjectSpace.each_object 1.38 4.89 0.12 122 0.98 1.64 RubyToken.def_token 1.27 5.00 0.11 2100 0.05 0.05 Symbol#to_s 1.27 5.11 0.11 392 0.28 0.64 Gem::Specification#copy_of 1.27 5.22 0.11 6492 0.02 0.02 Module#== 1.27 5.33 0.11 113 0.97 0.97 Gem::Specification#installation_path 1.04 5.42 0.09 340 0.26 0.26 Kernel.nil? 1.04 5.51 0.09 249 0.36 0.36 String#to_sym 1.04 5.60 0.09 519 0.17 0.19 Set#add 1.04 5.69 0.09 377 0.24 0.24 Hash#default