Class: BenchmarkDriver::RubyInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark_driver/ruby_interface.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output: nil, runner: nil) ⇒ RubyInterface

Returns a new instance of RubyInterface.

Parameters:

  • output (String, NilClass) (defaults to: nil)
  • runner (String, NilClass) (defaults to: nil)


24
25
26
27
28
29
30
# File 'lib/benchmark_driver/ruby_interface.rb', line 24

def initialize(output: nil, runner: nil)
  @prelude = ''
  @jobs = []
  @config = BenchmarkDriver::Config.new
  @config.output_type = output.to_s if output
  @config.runner_type = runner.to_s if runner
end

Class Method Details

.run(**args, &block) ⇒ Object



3
4
5
# File 'lib/benchmark_driver/ruby_interface.rb', line 3

def self.run(**args, &block)
  new(**args).tap { |x| block.call(x) }.run
end

Instance Method Details

#compare!Object

Backward compatibility. This is actually default now.



47
48
49
# File 'lib/benchmark_driver/ruby_interface.rb', line 47

def compare!
  @config.output_type = 'compare'
end

#prelude(script) ⇒ Object

Parameters:

  • script (String)


33
34
35
# File 'lib/benchmark_driver/ruby_interface.rb', line 33

def prelude(script)
  @prelude << "#{script}\n"
end

#report(name, script = nil) ⇒ Object

Parameters:

  • name (String)
    • Name shown on result output.

  • script (String, nil) (defaults to: nil)
    • Benchmarked script in String. If nil, name is considered as script too.



39
40
41
42
43
44
# File 'lib/benchmark_driver/ruby_interface.rb', line 39

def report(name, script = nil)
  if script.nil?
    script = name
  end
  @jobs << { benchmark: [{ name: name, script: script }] }
end

#runObject

Build jobs and run. This is NOT interface for users.



8
9
10
11
12
13
14
15
16
# File 'lib/benchmark_driver/ruby_interface.rb', line 8

def run
  jobs = @jobs.flat_map do |job|
    BenchmarkDriver::JobParser.parse({
      type: @config.runner_type,
      prelude: @prelude,
    }.merge!(job))
  end
  BenchmarkDriver::Runner.run(jobs, config: @config)
end