Class: Gruf::Timer

Inherits:
Object
  • Object
show all
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

Class Method Details

.timeTimer::Result

Times a given block by recording start and end times

result = Timer.time { do_my_thing }

Returns:



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