require 'schwad_performance_logger/version' require 'csv' require 'logger' require 'get_process_mem' require 'benchmark/ips' require 'schwad_performance_logger/schwad_performance_logger' module SchwadPerformanceLogger def self.new(opts={}) if opts.is_a?(Hash) PLogger.new(opts) else puts "I'm sorry, I don't know what you're trying to pass here!\n\n Please refer to the docs or pass an options hash https://github.com/oceanshq/schwad_performance_logger" end end def self.ips Benchmark.ips do |x| x.report("PerformanceLogMethod") do suppress_output do yield end end end end def self.time suppress_output do length_of_time = [] 10.times do start_time = Time.now yield length_of_time << Time.now - start_time end end puts "Average runtime #{length_of_time.sum / 10.0} seconds. Max time #{length_of_time.max}.seconds" end private def self.suppress_output original_stderr = $stderr.clone original_stdout = $stdout.clone $stderr.reopen(File.new('/dev/null', 'w')) $stdout.reopen(File.new('/dev/null', 'w')) yield ensure $stdout.reopen(original_stdout) $stderr.reopen(original_stderr) end end