Sha256: e0196ec7f9fff6d72d41d26b8753e9ad0e68abcd0e43e3665b46b9c671f9d6a4

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

if RUBY_ENGINE == 'opal'
  require 'opal/compiler'
  require 'nodejs'
  require 'corelib/string/unpack'
end

BEST_OF_N = Integer(ENV['BEST_OF_N']) rescue 1

require 'benchmark'

files = ARGV

if files.empty?
  files = File.read('benchmark/benchmarks').lines.map(&:strip).reject do |line|
    line.empty? || line.start_with?('#')
  end
end

files = files.shuffle

maxlen = files.max_by{|file| file.length}.length + 1

total_time = 0

files.each do |file|
  print file, " " * (maxlen - file.length)

  times = []

  if RUBY_ENGINE == 'opal'
    code = File.read(file)
    code = "Benchmark.measure { #{code} }"
    code = Opal.compile(code, file: file)

    BEST_OF_N.times do
      times << `eval(code)`
    end
  else
    code = File.read(file)
    code = "Benchmark.measure { #{code} }"

    BEST_OF_N.times do
      times << eval(code)
    end
  end

  time = times.min_by{|t| t.real}

  total_time += time.real

  print time.real, "\n"
end

bottom_line = "Executed #{ files.length } benchmark#{ 's' if files.length != 1} in #{ total_time } sec"
$stderr.print "=" * bottom_line.length, "\n"
$stderr.print bottom_line, "\n"

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
opal-1.6.1 benchmark/run.rb
opal-1.6.0 benchmark/run.rb
opal-1.6.0.rc1 benchmark/run.rb
opal-1.6.0.alpha1 benchmark/run.rb