16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/chap/benchmarking.rb', line 16
def benchmark_each(method, scope=nil)
class_eval <<-EOL
def #{method}_with_benchmark(*args,&block)
scope=#{scope.inspect}
result = nil
realtime = Benchmark.realtime do
result = #{method}_without_benchmark(*args,&block)
end
method_name = if args.empty?
"#{method}"
else
name = "#{method}" + '("' + args.join(',') + '")'
name = shorten_name(name)
end
method_name = scope + ': ' + method_name if scope
@@benchmarks << [method_name, realtime]
result
end
EOL
alias_method "#{method}_without_benchmark", method
alias_method method, "#{method}_with_benchmark"
end
|