- Add LogStash::StopWatch class for recording execution time of code

This commit is contained in:
Jordan Sissel 2009-10-25 03:14:42 +00:00
parent 18476af99b
commit 646a0948ed

View file

@ -16,4 +16,27 @@ module LogStash
return hash
end
end
class StopWatch
def initialize
start
end # def initialize
def start
@start = Time.now
end # def start
def duration
return Time.now - @start
end # def duration
def to_s(precision=-1)
# precision is for numbers, and '.' isn't a number, so pad for '.' if we
# want >0 precision
precision += 1 if precision > 0
return duration.to_s[0 .. precision]
end # def to_s
end # class StopWatch
end