Sha256: c12833af7e1c4ab82f919267baa56339cc89e13ebd54059db8f8b554e1434aea

Contents?: true

Size: 1.07 KB

Versions: 29

Compression:

Stored size: 1.07 KB

Contents

if RUBY_ENGINE == 'opal'
  require 'opal/compiler'
  require 'nodejs'
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

29 entries across 29 versions & 1 rubygems

Version Path
opal-1.5.1 benchmark/run.rb
opal-1.5.0 benchmark/run.rb
opal-1.5.0.rc1 benchmark/run.rb
opal-1.4.1 benchmark/run.rb
opal-1.4.0 benchmark/run.rb
opal-1.4.0.alpha1 benchmark/run.rb
opal-1.3.2 benchmark/run.rb
opal-1.3.1 benchmark/run.rb
opal-1.3.0 benchmark/run.rb
opal-1.3.0.rc1 benchmark/run.rb
opal-1.3.0.alpha1 benchmark/run.rb
opal-1.2.0 benchmark/run.rb
opal-1.2.0.beta1 benchmark/run.rb
opal-1.1.1 benchmark/run.rb
opal-1.1.1.rc1 benchmark/run.rb
opal-1.1.0 benchmark/run.rb
opal-1.1.0.rc1 benchmark/run.rb
opal-1.0.5 benchmark/run.rb
opal-1.0.4 benchmark/run.rb
opal-1.0.3 benchmark/run.rb