LoginSignup
196
162

More than 5 years have passed since last update.

Rubyで処理の時間計測方法

Last updated at Posted at 2014-05-16

ループ処理やクエリ実行した際に計測する方法。

start_time = Time.now

#処理

p "処理概要 #{Time.now - start_time}s"

追記

コメントよりBenckmarkというRubyの標準ライブラリがあるとのご指摘を頂いたので記述しておきます。

require 'benchmark'

result = Benchmark.realtime do
  # 処理
end
puts "処理概要 #{result}s"

require 'benchmark'でbenckmarkライブラリが使えるようになる。

196
162
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
196
162