Class: Benchmark::HTTP::Seconds
- Inherits:
-
Object
- Object
- Benchmark::HTTP::Seconds
- Defined in:
- lib/benchmark/http/seconds.rb
Constant Summary collapse
- UNITS =
["s", "ms", "µs"]
- SCALE =
UNITS.size - 1
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value) ⇒ Seconds
constructor
A new instance of Seconds.
- #scale ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ Seconds
Returns a new instance of Seconds.
31 32 33 |
# File 'lib/benchmark/http/seconds.rb', line 31 def initialize(value) @value = value end |
Class Method Details
.[](value) ⇒ Object
27 28 29 |
# File 'lib/benchmark/http/seconds.rb', line 27 def self.[](value) self.new(value) end |
Instance Method Details
#scale ⇒ Object
35 36 37 |
# File 'lib/benchmark/http/seconds.rb', line 35 def scale Math.log(@value) / Math.log(1000) end |
#to_s ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/benchmark/http/seconds.rb', line 39 def to_s scaled_value = @value scale = 0 while scaled_value < 1 && scale < SCALE scaled_value *= 1000 scale += 1 end return sprintf("%0.#{scale+1}f%s", scaled_value, UNITS.fetch(scale)) end |