Module: Axn::Internal::Timing
- Defined in:
- lib/axn/internal/timing.rb
Class Method Summary collapse
-
.elapsed_ms(start_time) ⇒ Object
Calculate elapsed time in milliseconds.
-
.elapsed_seconds(start_time) ⇒ Object
Calculate elapsed time in seconds.
-
.human_duration(millis) ⇒ Object
Format a millisecond value as a human-readable duration string.
-
.now ⇒ Object
Get the current monotonic time.
Class Method Details
.elapsed_ms(start_time) ⇒ Object
Calculate elapsed time in milliseconds
12 13 14 |
# File 'lib/axn/internal/timing.rb', line 12 def self.elapsed_ms(start_time) ((now - start_time) * 1000).round(3) end |
.elapsed_seconds(start_time) ⇒ Object
Calculate elapsed time in seconds
17 18 19 |
# File 'lib/axn/internal/timing.rb', line 17 def self.elapsed_seconds(start_time) (now - start_time).round(6) end |
.human_duration(millis) ⇒ Object
Format a millisecond value as a human-readable duration string
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/axn/internal/timing.rb', line 22 def self.human_duration(millis) case millis when 0...1_000 "#{millis.round(3)} milliseconds" when 1_000...60_000 "#{(millis / 1_000.0).round(3)} seconds" when 60_000...3_600_000 "#{(millis / 60_000.0).round(2)} minutes" else "#{(millis / 3_600_000.0).round(2)} hours" end end |
.now ⇒ Object
Get the current monotonic time
7 8 9 |
# File 'lib/axn/internal/timing.rb', line 7 def self.now Process.clock_gettime(Process::CLOCK_MONOTONIC) end |