module AdLint::Benchmark

Public Class Methods

_nullify_console_output() { || ... } click to toggle source
# File lib/adlint/benchmark/driver.rb, line 60
def _nullify_console_output(&block)
  orig_stdout = $stdout.dup
  orig_stderr = $stderr.dup
  dev_null = File.open(File::NULL, "w")
  $stdout.reopen(dev_null)
  $stderr.reopen(dev_null)
  yield
ensure
  $stdout.reopen(orig_stdout)
  $stderr.reopen(orig_stderr)
end
_run(target_name) click to toggle source
# File lib/adlint/benchmark/driver.rb, line 51
def _run(target_name)
  if target = AnalysisTarget.load(target_name)
    _nullify_console_output { target.analyze }
  else
    raise "no such target `#{target_name}'"
  end
end
run(target_name, count, print_time = false) click to toggle source
# File lib/adlint/benchmark/driver.rb, line 36
def run(target_name, count, print_time = false)
  if print_time
    require "benchmark"
    ::Benchmark.bm(target_name.length + 5, "total") do |x|
      total = count.times.reduce(::Benchmark::Tms.new) { |t, i|
        t += x.report("#{target_name} ##{i + 1}") { _run(target_name) }
      }
      [total]
    end
  else
    count.times { _run(target_name) }
  end
end

Private Instance Methods

_nullify_console_output() { || ... } click to toggle source
# File lib/adlint/benchmark/driver.rb, line 60
def _nullify_console_output(&block)
  orig_stdout = $stdout.dup
  orig_stderr = $stderr.dup
  dev_null = File.open(File::NULL, "w")
  $stdout.reopen(dev_null)
  $stderr.reopen(dev_null)
  yield
ensure
  $stdout.reopen(orig_stdout)
  $stderr.reopen(orig_stderr)
end
_run(target_name) click to toggle source
# File lib/adlint/benchmark/driver.rb, line 51
def _run(target_name)
  if target = AnalysisTarget.load(target_name)
    _nullify_console_output { target.analyze }
  else
    raise "no such target `#{target_name}'"
  end
end
run(target_name, count, print_time = false) click to toggle source
# File lib/adlint/benchmark/driver.rb, line 36
def run(target_name, count, print_time = false)
  if print_time
    require "benchmark"
    ::Benchmark.bm(target_name.length + 5, "total") do |x|
      total = count.times.reduce(::Benchmark::Tms.new) { |t, i|
        t += x.report("#{target_name} ##{i + 1}") { _run(target_name) }
      }
      [total]
    end
  else
    count.times { _run(target_name) }
  end
end