Sha256: 4e9c5871bdebce75a82da51cb4285db156fd9b9d4e3cf582960ce0d89a824ac1

Contents?: true

Size: 1.32 KB

Versions: 12

Compression:

Stored size: 1.32 KB

Contents

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

    # Build jobs and run. This is NOT interface for users.
    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

    #
    # Config APIs from here
    #

    # @param [String,NilClass] output
    # @param [String,NilClass] runner
    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

    # @param [String] script
    def prelude(script)
      @prelude << "#{script}\n"
    end

    # @param [String] name - Name shown on result output.
    # @param [String,nil] script - Benchmarked script in String. If nil, name is considered as script too.
    def report(name, script = nil)
      if script.nil?
        script = name
      end
      @jobs << { benchmark: [{ name: name, script: script }] }
    end

    # Backward compatibility. This is actually default now.
    def compare!
      @config.output_type = 'compare'
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
benchmark_driver-0.10.8 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.10.7 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.10.6 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.10.5 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.10.4 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.10.3 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.10.2 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.10.1 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.10.0 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.9.2 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.9.1 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.9.0 lib/benchmark_driver/ruby_interface.rb