Class: Timeit::Timer
- Inherits:
-
Object
- Object
- Timeit::Timer
- Defined in:
- lib/timeit.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #duration ⇒ Object
-
#initialize(start = Time.now) ⇒ Timer
constructor
A new instance of Timer.
- #rate ⇒ Object
- #reset_split! ⇒ Object
- #split ⇒ Object
- #split_rate ⇒ Object
- #tick!(count = 1) ⇒ Object
- #total_duration ⇒ Object
Constructor Details
#initialize(start = Time.now) ⇒ Timer
Returns a new instance of Timer.
10 11 12 13 14 15 16 17 18 |
# File 'lib/timeit.rb', line 10 def initialize(start = Time.now) @start_time = start @count = 0 @rate = 0 @split_time = start @split_count = 0 @split_rate = 0 end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
8 9 10 |
# File 'lib/timeit.rb', line 8 def count @count end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
8 9 10 |
# File 'lib/timeit.rb', line 8 def start_time @start_time end |
Instance Method Details
#duration ⇒ Object
20 21 22 23 24 |
# File 'lib/timeit.rb', line 20 def duration duration = Time.now - @start_time @rate = @count / duration duration end |
#rate ⇒ Object
49 50 51 |
# File 'lib/timeit.rb', line 49 def rate @rate end |
#reset_split! ⇒ Object
40 41 42 |
# File 'lib/timeit.rb', line 40 def reset_split! @split_time = @start_time end |
#split ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/timeit.rb', line 30 def split split = Time.now - @split_time @split_time = Time.now @split_rate = @split_count / split @split_count = 0 split end |
#split_rate ⇒ Object
53 54 55 |
# File 'lib/timeit.rb', line 53 def split_rate @split_rate end |
#tick!(count = 1) ⇒ Object
44 45 46 47 |
# File 'lib/timeit.rb', line 44 def tick!(count = 1) @count += count @split_count += count end |
#total_duration ⇒ Object
26 27 28 |
# File 'lib/timeit.rb', line 26 def total_duration Time.now - @start_time end |