Sha256: 2850b97df7bbf425c515fc888a8598715d62754fcd5f8b7b1241acca1ac61649

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
schwad_performance_logger-0.3.0 lib/schwad_performance_logger.rb