Sha256: e05f6e5a2c4b8e98b0f100fcb1f74916762143417c2c7b8dc39dadabe6c07cf5
Contents?: true
Size: 860 Bytes
Versions: 1
Compression:
Stored size: 860 Bytes
Contents
require "benchmeth/version" require "benchmark" module Benchmeth def self.included(base) base.send :extend, ClassMethods base.send :include, InstanceMethods end module ClassMethods 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 end module InstanceMethods def benchmeth(*method_names, &block) self.class.benchmeth(*method_names, &block) end end end Object.send :include, Benchmeth
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
benchmeth-0.0.1 | lib/benchmeth.rb |