Sha256: 23b0df9d404a0e6425e0f138035fca6af12fdc663256bb4497ae365abe673a3f
Contents?: true
Size: 986 Bytes
Versions: 7
Compression:
Stored size: 986 Bytes
Contents
# Helper methods for measuring, benchmarking, logging. # module Helpers module Measuring def log_performance(name, performed_on = '', &block) time_begin = Time.now.to_f lambda(&block).call duration = Time.now.to_f - time_begin # PerformanceLog.info("#{'%30s' % name}: #{'%2.10f' % duration} #{performed_on}") duration end # Returns a duration in seconds. # def timed(*args, &block) block_to_be_measured = lambda(&block) time_begin = Time.now.to_f block_to_be_measured.call(*args) Time.now.to_f - time_begin end def profiled_html(mode = :cpu_time, &block) require 'ruby-prof' RubyProf.measure_mode = "RubyProf::#{mode.to_s.upcase}".constantize result = RubyProf.profile &block printer = RubyProf::GraphHtmlPrinter.new(result) File.open('log/profiler.html', 'w') do |f| printer.print(f) end system 'open log/profiler.html' end end end
Version data entries
7 entries across 7 versions & 1 rubygems