Skip to content

Instantly share code, notes, and snippets.

@d4rky-pl
Last active August 29, 2015 14:22
Show Gist options
  • Save d4rky-pl/a34d4ec5d2b40447bcd6 to your computer and use it in GitHub Desktop.
Save d4rky-pl/a34d4ec5d2b40447bcd6 to your computer and use it in GitHub Desktop.
Benchmarking ExecJS with therubyracer and node
require 'benchmark'
require 'execjs'
require 'therubyracer'
js_code = '2+2'
STDOUT.sync = true
ExecJS.runtime = ExecJS::Runtimes::Node
Benchmark.bmbm(20) do |benchmark|
benchmark.report('node.js') do
100.times { ExecJS.eval(js_code) }
end
end
ExecJS.runtime = ExecJS::Runtimes::RubyRacer
Benchmark.bmbm(20) do |benchmark|
benchmark.report('therubyracer') do
100.times { ExecJS.eval(js_code) }
end
end
# RESULTS:
#
# Rehearsal ------------------------------------------------
# node.js 0.080000 0.050000 11.200000 ( 11.602124)
# -------------------------------------- total: 11.200000sec
#
# user system total real
# node.js 0.070000 0.050000 11.180000 ( 11.570431)
# Rehearsal ------------------------------------------------
# therubyracer 0.060000 0.020000 0.080000 ( 0.064798)
# --------------------------------------- total: 0.080000sec
#
# user system total real
# therubyracer 0.060000 0.010000 0.070000 ( 0.069190)
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment