Created
July 12, 2013 01:43
-
-
Save grosser/5980810 to your computer and use it in GitHub Desktop.
Audit time taken by different methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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