44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/benchmark_methods.rb', line 44
def cbenchmark(*cmethods)
interceptor = const_get("#{name.demodulize}Interceptor")
klass = const_get(name)
helper = const_set("BenchmarkMethods#{SecureRandom.hex}Helper", Module.new)
cmethods.each do |method_name|
interceptor.module_eval do
helper.send :define_singleton_method, :prepended do |base|
define_method(method_name) do |*args, &block|
BenchmarkMethods::measure("#{klass}.#{method_name}") do
super(*args, &block)
end
end
end
(class << klass; self; end).module_eval do
prepend(helper)
end
end
end
end
|