Sha256: 27b91581b2535b053c3365171c9cea1d74f709a0bcffaf02bc0953f4fd951625

Contents?: true

Size: 1.91 KB

Versions: 19

Compression:

Stored size: 1.91 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
      unless @executables.empty?
        @config.executables = @executables
      end

      jobs = @jobs.flat_map do |job|
        BenchmarkDriver::JobParser.parse({
          type: @config.runner_type,
          prelude: @prelude,
          loop_count: @loop_count,
        }.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, repeat_count: 1)
      @prelude = ''
      @loop_count = nil
      @jobs = []
      @config = BenchmarkDriver::Config.new
      @config.output_type = output.to_s if output
      @config.runner_type = runner.to_s if runner
      @config.repeat_count = Integer(repeat_count)
      @executables = []
    end

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

    # @param [Integer] count
    def loop_count(count)
      @loop_count = count
    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

    def output(type)
      @config.output_type = type
    end

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

    def rbenv(*versions)
      versions.each do |version|
        @executables << BenchmarkDriver::Rbenv.parse_spec(version)
      end
    end

    def verbose(level = 1)
      @config.verbose = level
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
benchmark_driver-0.14.10 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.14.9 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.14.8 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.14.7 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.14.6 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.14.5 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.14.4 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.14.3 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.14.2 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.14.0 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.13.3 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.13.2 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.13.1 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.13.0 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.12.0 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.11.1 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.11.0 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.10.16 lib/benchmark_driver/ruby_interface.rb
benchmark_driver-0.10.15 lib/benchmark_driver/ruby_interface.rb