Skip to content

Instantly share code, notes, and snippets.

@grosser
Created July 12, 2013 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grosser/5980810 to your computer and use it in GitHub Desktop.
Save grosser/5980810 to your computer and use it in GitHub Desktop.
Audit time taken by different methods
def audit(klass, method)
klass.class_eval do
define_method :"#{method}_with_audit" do |*args|
result = nil
time = Benchmark.realtime do
result = send(:"#{method}_without_audit", *args)
end
$time ||= {}
$time[klass] ||= {}
$time[klass][method] ||= 0
$time[klass][method] += time
result
end
alias_method_chain method, :audit
end
end
audit FooClass, :some_method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment