Skip to content

Instantly share code, notes, and snippets.

@kenji0x02
Last active January 2, 2016 02:59
Show Gist options
  • Save kenji0x02/8240589 to your computer and use it in GitHub Desktop.
Save kenji0x02/8240589 to your computer and use it in GitHub Desktop.
処理時間を測定するだけのシンプルなクラス。今までに50回くらい同じことを書いている気がするのでメモ。

StopWatch

Simple class to measure process time in Ruby. Please use this class, when you don't need to use profile library.

Usage

# Start stop watch
StopWatch.start

# Lap stop watch
StopWatch.lap
#=> 1.001137[s] from: test.rb:3:in `initialize' to: test.rb:10:in `method'
class StopWatch
def self.start
@@start_time = Time.now
@@start_back_trace = caller()[0]
end
def self.lap
begin
puts (Time.now - @@start_time).to_s + '[s] from: ' + @@start_back_trace + ' to: ' + caller()[0]
rescue
p $!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment