Skip to content

Instantly share code, notes, and snippets.

@yuku
Last active October 25, 2015 07:18
Show Gist options
  • Save yuku/4758afde9d4b5be2064c to your computer and use it in GitHub Desktop.
Save yuku/4758afde9d4b5be2064c to your computer and use it in GitHub Desktop.
execjs - therubyracer v.s. Node.js
require "benchmark/ips"
require "execjs"
require "open-uri"
source = open("http://coffeescript.org/extras/coffee-script.js").read
RUNTIMES = [
ExecJS::Runtimes::RubyRacer,
ExecJS::Runtimes::Node,
]
Benchmark.ips do |x|
RUNTIMES.each do |runtime|
x.report(runtime.name) do |renders|
ExecJS.runtime = runtime
renders.times do
ExecJS.eval("'red yellow blue'.split(' ')")
end
end
end
x.compare!
end
Benchmark.ips do |x|
RUNTIMES.each do |runtime|
x.report(runtime.name) do |renders|
ExecJS.runtime = runtime
context = ExecJS.compile(source)
renders.times do
context.call("CoffeeScript.compile", "square = (x) -> x * x", bare: true)
end
end
end
x.compare!
end
@yuku
Copy link
Author

yuku commented Oct 25, 2015

% ruby benchmark.rb
Calculating -------------------------------------
   therubyracer (V8)   141.000  i/100ms
        Node.js (V8)     1.000  i/100ms
-------------------------------------------------
   therubyracer (V8)      2.079k (±28.3%) i/s -      9.729k
        Node.js (V8)      4.921  (± 0.0%) i/s -     25.000

Comparison:
   therubyracer (V8):     2079.1 i/s
        Node.js (V8):        4.9 i/s - 422.47x slower

Calculating -------------------------------------
   therubyracer (V8)     7.000  i/100ms
        Node.js (V8)     1.000  i/100ms
-------------------------------------------------
   therubyracer (V8)    447.759  (±28.4%) i/s -      2.016k
        Node.js (V8)      2.824  (± 0.0%) i/s -     14.000  in   5.297662s

Comparison:
   therubyracer (V8):      447.8 i/s
        Node.js (V8):        2.8 i/s - 158.53x slower

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment