Class: Gruf::Timer
- Inherits:
-
Object
- Object
- Gruf::Timer
- Defined in:
- lib/gruf/timer.rb
Overview
Times a given block and returns the result and the elapsed time as a Float
result = Timer.time { do_my_thing }
Defined Under Namespace
Classes: Result
Class Method Summary collapse
-
.time ⇒ Timer::Result
Times a given block by recording start and end times.
Class Method Details
.time ⇒ Timer::Result
Times a given block by recording start and end times
result = Timer.time { do_my_thing }
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gruf/timer.rb', line 64 def self.time start_time = Time.now begin result = yield rescue GRPC::BadStatus, StandardError, GRPC::Core::CallError => e result = e end end_time = Time.now elapsed = (end_time - start_time) * 1000.0 Result.new(result, elapsed) end |