Skip to content

Instantly share code, notes, and snippets.

@grosser
Created Jul 12, 2013
Embed
What would you like to do?
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