measure only time units (s, ms) and if ms, value must be in ms.

This commit is contained in:
Denis Knauf 2013-04-10 18:21:01 +02:00
parent fccfe5a1d5
commit 4b8cc9eef8
2 changed files with 48 additions and 3 deletions

View file

@ -1,5 +1,8 @@
module NSCA
module PerformanceData
class TimeUnitExpected < Exception
end
class Base
extend Timeout
extend Benchmark
@ -17,6 +20,11 @@ module NSCA
end
def measure &block
f = case unit.to_s.to_sym
when :s then 1
when :ms then 1000
else raise TimeUnitExpected, "Unit must be seconds (s) or miliseconds (ms) not (#{unit})"
end
exception = ::Class.new Timeout::Error
timeout = max
m = realtime do
@ -25,7 +33,7 @@ module NSCA
rescue exception
end
end
new m
new f * m
end
def to_sym() label.to_sym end