Sha256: e41c34bf118b153fbe80d1e1ea43b345fa6d4eedef20130fc33c8df39f9998d3
Contents?: true
Size: 804 Bytes
Versions: 2
Compression:
Stored size: 804 Bytes
Contents
class Quandl::Client::Base module Benchmark extend ActiveSupport::Concern included do benchmark(:save) end module ClassMethods def benchmark(*names) names.each do |name| def_benchmark(name) end end private def def_benchmark(name) define_method(name) do |*args, &block| benchmark(name) do super(*args, &block) if defined?(super) end end end end def human_benchmarks benchmarks.sort_by{|k,v| v }.reverse.collect{|k,v| "#{k}: #{v.microseconds}ms" }.join(' | ') end def benchmarks @benchmarks ||= {} end private def benchmark(name, &block) timer = Time.now result = block.call self.benchmarks[name.to_sym] ||= timer.elapsed result end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
quandl_client-2.10.2 | lib/quandl/client/base/benchmark.rb |
quandl_client-2.10.1 | lib/quandl/client/base/benchmark.rb |