File: bench_execjs.rb

package info (click to toggle)
ruby-execjs 2.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,116 kB
  • sloc: javascript: 32,075; ruby: 1,036; makefile: 5
file content (20 lines) | stat: -rw-r--r-- 473 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
require 'benchmark'
require 'execjs'

TIMES = 10
SOURCE = File.read(File.expand_path("../fixtures/coffee-script.js", __FILE__)).freeze

Benchmark.bmbm do |x|
  ExecJS::Runtimes.runtimes.each do |runtime|
    next if !runtime.available? || runtime.deprecated?

    x.report(runtime.name) do
      ExecJS.runtime = runtime
      context = ExecJS.compile(SOURCE)

      TIMES.times do
        context.call("CoffeeScript.eval", "((x) -> x * x)(8)")
      end
    end
  end
end