Class: Ace::Compressor::Organisms::BenchmarkRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/compressor/organisms/benchmark_runner.rb

Constant Summary collapse

SUPPORTED_FORMATS =
%w[table json].freeze
SUPPORTED_MODES =
CompressionRunner::SUPPORTED_MODES

Instance Method Summary collapse

Constructor Details

#initialize(paths, modes: nil, format: "table", verbose: false) ⇒ BenchmarkRunner

Returns a new instance of BenchmarkRunner.



13
14
15
16
17
18
19
20
# File 'lib/ace/compressor/organisms/benchmark_runner.rb', line 13

def initialize(paths, modes: nil, format: "table", verbose: false)
  @paths = Array(paths)
  @modes = parse_modes(modes)
  @format = (format || "table").to_s
  @verbose = verbose
  @resolver = ExactCompressor.new(paths, verbose: verbose)
  @retention = Ace::Compressor::Atoms::RetentionReporter.new
end

Instance Method Details

#callObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/ace/compressor/organisms/benchmark_runner.rb', line 22

def call
  raise Ace::Compressor::Error, "Unsupported format '#{@format}'. Use --format table or json" unless SUPPORTED_FORMATS.include?(@format)

  sources = @resolver.resolve_sources
  per_source = sources.map { |source| benchmark_source(source) }
  {
    "sources" => per_source,
    "summary" => summarize(per_source)
  }
end

#render(report) ⇒ Object



33
34
35
36
37
# File 'lib/ace/compressor/organisms/benchmark_runner.rb', line 33

def render(report)
  return JSON.pretty_generate(report) if @format == "json"

  render_table(report.fetch("sources"))
end