Skip to content

Instantly share code, notes, and snippets.

@Irostovsky
Created July 19, 2018 09:26
Show Gist options
  • Save Irostovsky/52e2e17784ba45d64bc6098c313b794b to your computer and use it in GitHub Desktop.
Save Irostovsky/52e2e17784ba45d64bc6098c313b794b to your computer and use it in GitHub Desktop.
Bench timer
# frozen_string_literal: true
module Utils
class Timer
def self.call(name)
t = Time.zone.now
result = yield
time = ((Time.zone.now - t).to_d * 1000).to_i
p "++++++++++ #{name}: #{time}ms"
{ result: result, time: time }
end
end
end
@Irostovsky
Copy link
Author

To use:

def my_meth
  timer_res = Utils::TImer.call 'my_meth' do 
    //some_code_here
  end
  timer_res[:result]
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment