Class: Reviewer::Shell::Timer
- Inherits:
-
Object
- Object
- Reviewer::Shell::Timer
- Defined in:
- lib/reviewer/shell/timer.rb
Overview
Provides a structured interface for measuring realtime main while running comamnds
Instance Attribute Summary collapse
-
#main ⇒ Object
Returns the value of attribute main.
-
#prep ⇒ Float?
The preparation time in seconds.
Instance Method Summary collapse
-
#initialize(prep: nil, main: nil) ⇒ Timer
constructor
A timer that tracks preparation and main execution times separately.
-
#main_seconds ⇒ Float
The main execution time rounded to two decimal places.
-
#prep_percent ⇒ Integer?
The percentage of total time spent on preparation.
-
#prep_seconds ⇒ Float
The preparation time rounded to two decimal places.
-
#prepped? ⇒ Boolean
Whether both prep and main times have been recorded.
-
#record_main ⇒ Float
Records the execution time for the block and assigns it to the
maintime. -
#record_prep ⇒ Float
Records the execution time for the block and assigns it to the
preptime. -
#total ⇒ Float
The total time (prep + main) without rounding.
-
#total_seconds ⇒ Float
The total execution time (prep + main) rounded to two decimal places.
Constructor Details
#initialize(prep: nil, main: nil) ⇒ Timer
A timer that tracks preparation and main execution times separately. Times can be passed directly or recorded using record_prep and record_main.
21 22 23 24 |
# File 'lib/reviewer/shell/timer.rb', line 21 def initialize(prep: nil, main: nil) @prep = prep @main = main end |
Instance Attribute Details
#main ⇒ Object
Returns the value of attribute main.
13 |
# File 'lib/reviewer/shell/timer.rb', line 13 attr_reader :prep, :main |
#prep ⇒ Float?
Returns the preparation time in seconds.
13 14 15 |
# File 'lib/reviewer/shell/timer.rb', line 13 def prep @prep end |
Instance Method Details
#main_seconds ⇒ Float
The main execution time rounded to two decimal places
46 |
# File 'lib/reviewer/shell/timer.rb', line 46 def main_seconds = main.round(2) |
#prep_percent ⇒ Integer?
The percentage of total time spent on preparation
66 67 68 69 70 |
# File 'lib/reviewer/shell/timer.rb', line 66 def prep_percent return nil unless prepped? (prep / total.to_f * 100).round end |
#prep_seconds ⇒ Float
The preparation time rounded to two decimal places
41 |
# File 'lib/reviewer/shell/timer.rb', line 41 def prep_seconds = prep.round(2) |
#prepped? ⇒ Boolean
Whether both prep and main times have been recorded
61 |
# File 'lib/reviewer/shell/timer.rb', line 61 def prepped? = [prep, main].all? |
#record_main ⇒ Float
Records the execution time for the block and assigns it to the main time
36 |
# File 'lib/reviewer/shell/timer.rb', line 36 def record_main(&) = @main = record(&) |
#record_prep ⇒ Float
Records the execution time for the block and assigns it to the prep time
30 |
# File 'lib/reviewer/shell/timer.rb', line 30 def record_prep(&) = @prep = record(&) |
#total ⇒ Float
The total time (prep + main) without rounding
56 |
# File 'lib/reviewer/shell/timer.rb', line 56 def total = [prep, main].compact.sum |
#total_seconds ⇒ Float
The total execution time (prep + main) rounded to two decimal places
51 |
# File 'lib/reviewer/shell/timer.rb', line 51 def total_seconds = total.round(2) |