Skip to content

Instantly share code, notes, and snippets.

@jarib
Created July 3, 2014 14:20
Show Gist options
  • Save jarib/c6599fbab7fbf1e59524 to your computer and use it in GitHub Desktop.
Save jarib/c6599fbab7fbf1e59524 to your computer and use it in GitHub Desktop.
Calculating -------------------------------------
ruby 3 i/100ms
java -client 1 i/100ms
java -server 1 i/100ms
node 3 i/100ms
python 4 i/100ms
-------------------------------------------------
ruby 37.9 (±2.6%) i/s - 381 in 10.054042s
java -client 11.6 (±0.0%) i/s - 117 in 10.054871s
java -server 11.6 (±0.0%) i/s - 116 in 9.997524s
node 32.6 (±3.1%) i/s - 327 in 10.029777s
python 44.0 (±2.3%) i/s - 444 in 10.091227s
Comparison:
python: 44.0 i/s
ruby: 37.9 i/s - 1.16x slower
node: 32.6 i/s - 1.35x slower
java -client: 11.6 i/s - 3.78x slower
java -server: 11.6 i/s - 3.79x slower
require 'benchmark/ips' # gem install benchmark-ips
unless File.file?("Hello.class")
File.open('Hello.java', 'w') { |io|
io << <<-CODE
public class Hello {
public static void main(String[] args) {
int i = 2 + 2;
}
}
CODE
}
ok = system "javac", "Hello.java"
ok or abort "could not compile Hello.java"
end
Benchmark.ips do |x|
x.time = 10
x.warmup = 2
x.report("ruby") { system "/usr/bin/ruby", "-e", "2 + 2" }
x.report("java -client") { system "java", "-client", "Hello" }
x.report("java -server") { system "java", "-server", "Hello" }
x.report("node") { system "/opt/boxen/nodenv/versions/v0.10.28/bin/node", "-e", "2 + 2" }
x.report("python") { system "python", "-c", "2 + 2" }
x.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment