Skip to content
keita edited this page Sep 12, 2010 · 1 revision

Home (English)

BenchmarkX

BenchmarkX は、通常のBenchmarkモジュールを拡張して、その結果を"Gruff":http://nubyonrails.com/pages/gruff を用いた美しいグラフとして出力するためのライブラリです。

インストール


% sudo gem install

使い方

BenchmarkX は標準添付の Benchmark モジュール(benchmark.rb) とほとんど同じ振舞いをします。


require "benchmarkx"

BenchmarkX.bm |x| do
    # グラフのファイル名を設定します
    x.filename = "graph.png"
    # グラフの題名を設定します
    x.gruff.title = "#{n} times iterations of `a = \"1\"'"
    x.report("for:")   {for i in 1..n; a = "1"; end} # Benchmark::measure
    x.report("times:") {n.times do   ; a = "1"; end}
    x.report("upto:")  {1.upto(n) do ; a = "1"; end}
end

このベンチマーク結果は次のようなグラフとなります。

generated by BenchmarkX 001

また標準出力に通常のテキスト版の結果を表示します。


50000 times iterations of `a = "1"'
             user     system      total        real
for:     0.040000   0.010000   0.050000 (  0.062325)
times:   0.030000   0.000000   0.030000 (  0.049322)
upto:    0.050000   0.010000   0.060000 (  0.065992)

Links

Clone this wiki locally