Sha256: 7e59b0ebe6890a7266b83a29cfcffc1444e942c10020ebc3cd9735e0880dad80
Contents?: true
Size: 1.8 KB
Versions: 13
Compression:
Stored size: 1.8 KB
Contents
module Benchmark::Driver::YamlParser class << self # @param [String] prelude # @param [Integer,nil] loop_count # @param [String,Array<String,Hash{ Symbol => String }>,Hash{ Symbol => String }] benchmark # @return [Array<Benchmark::Driver::Configuration::Job>] def parse(prelude: '', loop_count: nil, benchmark:) jobs = parse_benchmark(benchmark) jobs.each do |job| job.prelude = prelude job.loop_count ||= loop_count end end private # Parse "benchmark" declarative. This may have multiple benchmarks. # @param [String,Array<String,Hash{ Symbol => String }>,Hash{ Symbol => String }] benchmark def parse_benchmark(benchmark) case benchmark when String [parse_each_benchmark(benchmark)] when Array benchmark.map { |b| parse_each_benchmark(b) } when Hash benchmark.map do |key, value| Benchmark::Driver::Configuration::Job.new(key.to_s, value) end else raise ArgumentError.new("benchmark must be String, Array or Hash, but got: #{benchmark.inspect}") end end # Parse one benchmark specified in "benchmark" declarative. # @param [String,Hash{ Symbol => String }>] job def parse_each_benchmark(benchmark) case benchmark when String Benchmark::Driver::Configuration::Job.new(benchmark, benchmark) when Hash parse_job(benchmark) else raise ArgumentError.new("Expected String or Hash in element of benchmark, but got: #{benchmark.inspect}") end end # @param [String,nil] name # @param [String] script # TODO: support benchmark-specific prelude def parse_job(name: nil, script:) name = script if name.nil? Benchmark::Driver::Configuration::Job.new(name, script) end end end
Version data entries
13 entries across 13 versions & 1 rubygems