Ruby 2.2.0 リファレンスマニュアル > ライブラリ一覧 > benchmarkライブラリ > Benchmarkモジュール > measure

module function Benchmark.#measure

measure(label = "") { ... } -> Benchmark::Tms[permalink][rdoc]

与えられたブロックを実行して、経過した時間を Process.#times で計り、 Benchmark::Tms オブジェクトを生成して返します。

Benchmark::Tms オブジェクトには to_s が定義されているので、基本的には以下のように使います。


require 'benchmark'

puts Benchmark::CAPTION
puts Benchmark.measure { "a"*1_000_000 }

#=>
#
#     user     system      total        real
# 1.166667   0.050000   1.216667 (  0.571355)