Skip to content

Instantly share code, notes, and snippets.

@postmodern
Created April 12, 2010 06:56
Show Gist options
  • Save postmodern/363340 to your computer and use it in GitHub Desktop.
Save postmodern/363340 to your computer and use it in GitHub Desktop.
Before getting into yet-another-pointless language war, here are some recent numbers. Argue less, code more.
#!/bin/sh
time python fib.py
rvm use 1.8.6
time ruby fib.rb
rvm use 1.8.7
time ruby fib.rb
rvm use 1.9.1
time ruby fib.rb
rvm use 1.9.2
time ruby fib.rb
rvm use jruby
time ruby fib.rb
javac Fib.java
jar cf Fib.jar Fib.class
time java -classpath Fib.jar Fib
gcc -O2 fib.c -o fib
time ./fib
#include <stdio.h>
int fib(int n)
{
if (n == 0 || n == 1)
{
return n;
}
else
{
return fib(n-1) + fib(n-2);
}
}
int main()
{
int i;
for (i=0; i<36; i++)
{
printf("n=%d => %d\n",i,fib(i));
}
return 0;
}
public class Fib {
public static int fib(int n) {
if (n == 0 || n == 1)
return n;
return (fib(n-1) + fib(n-2));
}
public static void main(String[] args) {
for (int i = 0; i < 36; i++)
System.out.println("n=" + i + " => " + fib(i));
}
}
def fib(n):
if n == 0 or n == 1:
return n
else:
return fib(n-1) + fib(n-2)
for i in range(36):
print "n=%d => %d" % (i, fib(i))
def fib(n)
if n == 0 || n == 1
n
else
fib(n-1) + fib(n-2)
end
end
36.times do |i|
puts "n=#{i} => #{fib(i)}"
end
Linux localhost 2.6.28 #8 SMP Sun May 9 22:53:00 PDT 2010 x86_64 AMD Athlon(tm) 64 Processor 3400+ AuthenticAMD GNU/Linux
python 2.6.4:
real 0m36.433s
user 0m34.850s
sys 0m0.080s
ruby 1.8.6:
real 1m1.663s
user 1m0.200s
sys 0m0.160s
ruby 1.8.7:
real 1m11.179s
user 1m9.000s
sys 0m0.240s
ruby 1.9.1:
real 0m13.813s
user 0m12.550s
sys 0m0.030s
ruby 1.9.2-preview1:
real 0m14.846s
user 0m13.550s
sys 0m0.070s
jruby 1.4.0:
real 0m30.871s
user 0m25.800s
sys 0m0.360s
java 1.6.0_0
real 0m0.577s
user 0m0.360s
sys 0m0.030s
C:
real 0m0.292s
user 0m0.240s
sys 0m0.010s
@postmodern
Copy link
Author

One should note, that I'm running the OpenJDK 64-Bit Server VM. Currently a 64-bit Client VM is still not available. The increased start-up time of the Server VM impacted the total run-time of JRuby, but did not seem to effect the compiled Fib.java.

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