Module: Benchmeth::ClassMethods

Defined in:
lib/benchmeth.rb

Instance Method Summary collapse

Instance Method Details

#benchmeth(*method_names, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/benchmeth.rb', line 13

def benchmeth(*method_names, &block)
  method_names.each do |method_name|
    method_name = method_name.to_sym
    self.send :alias_method, :"#{method_name}_without_benchmark", method_name
    self.send :define_method, method_name do |*args|
      result = nil
      realtime = Benchmark.realtime { result = self.send(:"#{method_name}_without_benchmark", *args) }
      block.call(method_name, realtime)
      result
    end
  end
end