Class: Vedeu::Logging::Timer
- Inherits:
-
Object
- Object
- Vedeu::Logging::Timer
- Defined in:
- lib/vedeu/logging/timer.rb
Overview
Measure the duration. Used for debugging.
Instance Attribute Summary collapse
- #message ⇒ String readonly protected
- #started ⇒ Time readonly protected
Class Method Summary collapse
-
.timer(message = '', &block) ⇒ void
The return value of the executed block.
Instance Method Summary collapse
-
#elapsed ⇒ Float
protected
Returns the elapsed time in milliseconds with 3 decimal places.
-
#initialize(message = '') ⇒ Vedeu::Logging::Timer
constructor
Returns a new instance of Vedeu::Logging::Timer.
-
#measure ⇒ void
Write an entry to the log file stating how long a section of code took in milliseconds.
Constructor Details
#initialize(message = '') ⇒ Vedeu::Logging::Timer
Returns a new instance of Vedeu::Logging::Timer.
29 30 31 32 |
# File 'lib/vedeu/logging/timer.rb', line 29 def initialize( = '') = @started = Time.now.to_f end |
Instance Attribute Details
#message ⇒ String (readonly, protected)
54 55 56 |
# File 'lib/vedeu/logging/timer.rb', line 54 def end |
#started ⇒ Time (readonly, protected)
50 51 52 |
# File 'lib/vedeu/logging/timer.rb', line 50 def started @started end |
Class Method Details
.timer(message = '', &block) ⇒ void
This method returns an undefined value.
Returns The return value of the executed block.
19 20 21 |
# File 'lib/vedeu/logging/timer.rb', line 19 def timer( = '', &block) new().measure(&block) end |
Instance Method Details
#elapsed ⇒ Float (protected)
Returns the elapsed time in milliseconds with 3 decimal places.
60 61 62 |
# File 'lib/vedeu/logging/timer.rb', line 60 def elapsed ((Time.now.to_f - started) * 1000).round(3) end |
#measure ⇒ void
This method returns an undefined value.
Write an entry to the log file stating how long a section of code took in milliseconds. Useful for debugging performance.
38 39 40 41 42 43 44 |
# File 'lib/vedeu/logging/timer.rb', line 38 def measure work = yield Vedeu.log(type: :timer, message: "#{message} took #{elapsed}ms.") work end |