module BenchmarkInterface

Copyright © 2016 Oracle and/or its affiliates. All rights reserved. This code is released under a tri EPL/GPL/LGPL license. You can use it, redistribute it and/or modify it under the terms of the:

Eclipse Public License version 1.0 GNU General Public License version 2 GNU Lesser General Public License version 2.1

Copyright © 2016 Oracle and/or its affiliates. All rights reserved. This code is released under a tri EPL/GPL/LGPL license. You can use it, redistribute it and/or modify it under the terms of the:

Eclipse Public License version 1.0 GNU General Public License version 2 GNU Lesser General Public License version 2.1

Copyright © 2016 Oracle and/or its affiliates. All rights reserved. This code is released under a tri EPL/GPL/LGPL license. You can use it, redistribute it and/or modify it under the terms of the:

Eclipse Public License version 1.0 GNU General Public License version 2 GNU Lesser General Public License version 2.1

Copyright © 2016 Oracle and/or its affiliates. All rights reserved. This code is released under a tri EPL/GPL/LGPL license. You can use it, redistribute it and/or modify it under the terms of the:

Eclipse Public License version 1.0 GNU General Public License version 2 GNU Lesser General Public License version 2.1

Copyright © 2016 Oracle and/or its affiliates. All rights reserved. This code is released under a tri EPL/GPL/LGPL license. You can use it, redistribute it and/or modify it under the terms of the:

Eclipse Public License version 1.0 GNU General Public License version 2 GNU Lesser General Public License version 2.1

Copyright © 2016 Oracle and/or its affiliates. All rights reserved. This code is released under a tri EPL/GPL/LGPL license. You can use it, redistribute it and/or modify it under the terms of the:

Eclipse Public License version 1.0 GNU General Public License version 2 GNU Lesser General Public License version 2.1

Copyright © 2016 Oracle and/or its affiliates. All rights reserved. This code is released under a tri EPL/GPL/LGPL license. You can use it, redistribute it and/or modify it under the terms of the:

Eclipse Public License version 1.0 GNU General Public License version 2 GNU Lesser General Public License version 2.1

Copyright © 2016 Oracle and/or its affiliates. All rights reserved. This code is released under a tri EPL/GPL/LGPL license. You can use it, redistribute it and/or modify it under the terms of the:

Eclipse Public License version 1.0 GNU General Public License version 2 GNU Lesser General Public License version 2.1

Copyright © 2016 Oracle and/or its affiliates. All rights reserved. This code is released under a tri EPL/GPL/LGPL license. You can use it, redistribute it and/or modify it under the terms of the:

Eclipse Public License version 1.0 GNU General Public License version 2 GNU Lesser General Public License version 2.1

Copyright © 2016 Oracle and/or its affiliates. All rights reserved. This code is released under a tri EPL/GPL/LGPL license. You can use it, redistribute it and/or modify it under the terms of the:

Eclipse Public License version 1.0 GNU General Public License version 2 GNU Lesser General Public License version 2.1

Copyright © 2016 Oracle and/or its affiliates. All rights reserved. This code is released under a tri EPL/GPL/LGPL license. You can use it, redistribute it and/or modify it under the terms of the:

Eclipse Public License version 1.0 GNU General Public License version 2 GNU Lesser General Public License version 2.1

Copyright © 2016 Oracle and/or its affiliates. All rights reserved. This code is released under a tri EPL/GPL/LGPL license. You can use it, redistribute it and/or modify it under the terms of the:

Eclipse Public License version 1.0 GNU General Public License version 2 GNU Lesser General Public License version 2.1

Copyright © 2016 Oracle and/or its affiliates. All rights reserved. This code is released under a tri EPL/GPL/LGPL license. You can use it, redistribute it and/or modify it under the terms of the:

Eclipse Public License version 1.0 GNU General Public License version 2 GNU Lesser General Public License version 2.1

Constants

NON_MRI_INDICATORS
VERSION

Public Class Methods

benchmark(name=nil, &block) click to toggle source
# File lib/benchmark-interface.rb, line 22
def self.benchmark(name=nil, &block)
  BenchmarkInterface::BenchmarkSet.current.register name, block
end
help() click to toggle source
# File lib/benchmark-interface/run.rb, line 90
def self.help
  puts "Benchmark-Interface #{VERSION}"
  puts
  puts 'benchmark benchmark-files.rb... [benchmark names...] [options]'
  puts
  puts 'Backends:'
  puts '  --simple'
  puts '  --bips (default)'
  puts '  --bm'
  puts '  --bmbm'
  puts '  --bench9000'
  puts
  puts 'Options:'
  puts '  --no-scale        Don\'t scale benchmarks for backends that expects benchmarks to take about a second'
  puts '  --show-rewrite    Show rewritten MRI benchmarks'
  puts '  --cache           Cache MRI rewrites'
  puts '  --use-cache       Use cached MRI rewrites'
  puts '  --time n          Run for n seconds, if the backend supports that'
  exit 1
end
run(args) click to toggle source
# File lib/benchmark-interface/run.rb, line 16
def self.run(args)
  set = BenchmarkInterface::BenchmarkSet.new

  backend = BenchmarkInterface::Backends::Bips
  names = []
  
  options = {
    '--no-scale' => false,
    '--use-cache' => false,
    '--show-rewrite' => false,
    '--cache' => false,
    '--time' => 10
  }

  to_load = []

  n = 0
  while n < args.size
    arg = args[n]
    if arg.start_with? '-'
      case arg
        when '--help', '-h', '-help', '--version', '-v', '-version'
          help
        when '--simple'
          backend = BenchmarkInterface::Backends::Simple
        when '--bips'
          backend = BenchmarkInterface::Backends::Bips
        when '--bm'
          backend = BenchmarkInterface::Backends::Bm
        when '--bmbm'
          backend = BenchmarkInterface::Backends::BmBm
        when '--bench9000'
          backend = BenchmarkInterface::Backends::Bench9000
        when '--time'
          options[arg] = Integer(args[n + 1])
          n += 1
        else
          abort "unknown option #{arg}" unless options.keys.include?(arg)
          options[arg] = true
      end
    elsif arg.include?('.rb')
      to_load.push arg
    else
      names.push arg
    end
    n += 1
  end

  to_load.each do |path|
    source = File.read(path)
    if NON_MRI_INDICATORS.any? { |t| source.include?(t) } || source =~ /benchmark.*\{/ || source =~ /benchmark.*do/
      set.load_benchmarks path
    else
      set.load_mri_benchmarks path, options
    end
  end

  set.prepare

  if set.benchmarks.empty?
    abort 'No benchmarks found!'
  end

  names.each do |name|
    unless set.benchmark(name)
      abort "Unknown benchmark #{name}"
    end
  end

  names = set.benchmarks.map(&:name) if names.empty?

  backend.run set, names, options
end