(转)斐波那契算法 各个开发语言排名

http://fengmk2.github.io/blog/2011/fibonacci/nodejs-python-php-ruby-lua.html

Home | Prev

fibonacci(40) benchmark

Node.js is Cancer show a wrong way to use nodejs. But the test code Fibonacci is so funny. I implement the fibonacci function in other Dynamic Languages for comparison testing.

Languages

Dynamic

Static

If you want to help add more dynamic languagues, please leave the implement code in comments.

Results

(^_^) c > java > go > scala > luajit > nodejs > ruby 2.0.0-p0 > pypy > ruby 1.9.3+ > lua > php > python > perl > ruby 1.8.x (T_T)

Language Times (user) Position Version
c with -O2 0m0.202s #0 i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 
(Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
nodejs + cpp module 0m1.001s #1 v0.8.8, gcc -O2
java 0m1.305s #2 Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)
go 0m1.667s #3 go version go1.0.2
scala 0m1.808s #4 Scala code runner version 2.9.2 -- Copyright 2002-2011, LAMP/EPFL
luajit 0m2.579s #5 LuaJIT 2.0.0-beta10 -- Copyright (C) 2005-2012 Mike Pall.
nodejs 0m2.872s #6 v0.8.8
ruby 2.0.0-p0 0m27.777s #7 ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]
pypy 0m30.010s #8 Python 2.7.2 (341e1e3821ff, Jun 07 2012, 15:42:54) [PyPy 1.9.0 with GCC 4.2.1]
ruby 1.9.x 0m37.404s #9 ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.1.0]
lua 0m40.709s #10 Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
jython 0m53.699s #11 Jython 2.5.2
php 1m17.728s #12 PHP 5.4.6 (cli) (built: Sep 8 2012 23:49:53)
python 1m17.979s #13 Python 2.7.2
perl 2m41.259s #14 This is perl 5, version 12, subversion 4 (v5.12.4) built for darwin-thread-multi-2level
ruby 1.8.x 3m35.135s #15 ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]

lua use local function will get better performance.

fibonacci(40) benchmark result:

c

i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >#include <stdio.h>

int fibonacci(n) {
 
if (n < 2) {
   
return n;
 
}
 
return fibonacci(n - 2) + fibonacci(n - 1);
}

int main() {
  printf
("%d\n", fibonacci(40));
 
return 0;
}
de>

gcc -O0

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m4.145s
user  
0m3.892s
sys
0m0.012s
de>

gcc -O1

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m2.732s
user  
0m2.610s
sys
0m0.009s
de>

gcc -O2

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m0.249s
user  
0m0.202s
sys
0m0.004s
de>

gcc -O3

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m0.293s
user  
0m0.202s
sys
0m0.004s
de>

java

java version "1.6.0_35" Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811) Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >public class Fibonacci {
 
public static int fib(int n) {
   
if (n < 2) {
     
return n;
   
} else {
     
return fib(n - 1) + fib(n - 2);
   
}
 
}

 
public static void main(String[] args) {
   
System.out.print(fib(40) + "\n");
 
}
}
de>
de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m1.413s
user  
0m1.305s
sys
0m0.063s
de>

scala

Scala code runner version 2.9.2 -- Copyright 2002-2011, LAMP/EPFL

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >object Fibonacci {
 
def fib(n: Int): Int = n match {
   
case 0 | 1 => n
   
case _ => fib(n -1) + fib(n-2)
 
}

 
def main(args: Array[String]) {
    println
(fib(40));
 
}
}
de>
de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m1.909s
user  
0m1.808s
sys
0m0.121s
de>

go

go version go1.0.2

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >package main

import "fmt"

func fibonacci
(n int) int{
 
if (n < 2) {
   
return n
 
}
 
return fibonacci(n - 2) + fibonacci(n - 1)
}

func main
() {
  fmt
.Println(fibonacci(40))
}
de>
de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m1.732s
user  
0m1.667s
sys
0m0.006s
de>

nodejs

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >function fibonacci(n) {
 
if (n < 2) {
   
return n;
 
}
 
return fibonacci(n - 2) + fibonacci(n - 1);
}

console
.log(fibonacci(40));
de>

v0.2.6

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m4.959s
user  
0m4.699s
sys
0m0.028s
de>

v0.3.8

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m4.961s
user  
0m4.867s
sys
0m0.022s
de>

v0.4.12

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m7.544s
user  
0m7.219s
sys
0m0.030s
de>

v0.6.19

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m5.264s
user  
0m5.062s
sys
0m0.040s
de>

v0.6.20

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m5.413s
user  
0m5.195s
sys
0m0.038s
de>

v0.6.21-pre

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m5.081s
user  
0m4.906s
sys
0m0.037s
de>

v0.7.12

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m2.964s
user  
0m2.867s
sys
0m0.029s
de>

v0.8.0

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m3.034s
user  
0m2.868s
sys
0m0.029s
de>

v0.8.1

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m3.064s
user  
0m2.863s
sys
0m0.032s
de>

v0.8.3

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m3.024s
user  
0m2.855s
sys
0m0.030s
de>

v0.8.6

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m3.046s
user  
0m2.854s
sys
0m0.030s
de>

v0.8.7

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m3.258s
user  
0m2.933s
sys
0m0.033s
de>

v0.8.8

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m3.052s
user  
0m2.866s
sys
0m0.031s
de>

v0.9.1

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m3.190s
user  
0m2.852s
sys
0m0.032s
de>

nodejs + cpp module

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >var fibonacci = require('./build/Release/cppfibonacci').fibonacci;
console
.log(fibonacci(40));
de>

waf 1.5.16 (7610:7647M) v0.4.12

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m1.374s
user  
0m1.012s
sys
0m0.024s
de>

waf 1.5.16 (7610:7647M) v0.6.20

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m1.063s
user  
0m1.000s
sys
0m0.018s
de>

waf 1.5.16 (7610:7647M) v0.8.8

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m1.076s
user  
0m1.001s
sys
0m0.015s
de>

luajit

LuaJIT 2.0.0-beta10 -- Copyright (C) 2005-2012 Mike Pall. http://luajit.org/

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >function fibonacci(n)
 
if n < 2 then
   
return n
 
end
 
return fibonacci(n - 2) + fibonacci(n - 1)
end

io
.write(fibonacci(40), "\n")
de>
de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m2.847s
user  
0m2.579s
sys
0m0.013s
de>

using 'local'

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >local function fibonacci(n)
 
if n < 2 then
   
return n
 
end
 
return fibonacci(n - 2) + fibonacci(n - 1)
end

io
.write(fibonacci(40), "\n")
de>
de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m2.536s
user  
0m2.490s
sys
0m0.006s
de>

pypy

Python 2.7.2 (341e1e3821ff, Jun 07 2012, 15:42:54) [PyPy 1.9.0 with GCC 4.2.1]

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >def fibonacci(n):
   
if n < 2:
       
return n
   
return fibonacci(n - 2) + fibonacci(n - 1)

print fibonacci(40)
de>
de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m34.082s
user  
0m30.010s
sys
0m0.303s
de>

ruby 1.9.x

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >def fibonacci(n)
 
if n < 2
   
return n
 
end
 
return fibonacci(n - 2) + fibonacci(n - 1)
end

puts fibonacci
(40)
de>

ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.1.0]

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m39.972s
user  
0m37.404s
sys
0m0.124s
de>

ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m29.078s
user  
0m27.777s
sys
0m0.072s
de>

lua

Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >function fibonacci(n)
 
if n < 2 then
   
return n
 
end
 
return fibonacci(n - 2) + fibonacci(n - 1)
end

io
.write(fibonacci(40), "\n")
de>
de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m42.961s
user  
0m40.709s
sys
0m0.098s
de>

using 'local'

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >local function fibonacci(n)
 
if n < 2 then
   
return n
 
end
 
return fibonacci(n - 2) + fibonacci(n - 1)
end

io
.write(fibonacci(40), "\n")
de>
de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m37.178s
user  
0m35.887s
sys
0m0.081s
de>

python && jython

Python 2.7.2

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >def fibonacci(n):
   
if n < 2:
       
return n
   
return fibonacci(n - 2) + fibonacci(n - 1)

print fibonacci(40)
de>
de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
1m23.989s
user  
1m17.979s
sys
0m0.303s
de>

Jython 2.5.2

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
0m58.651s
user  
0m53.699s
sys
0m1.945s
de>

php

PHP 5.3.13 with Suhosin-Patch (cli) (built: Jun 20 2012 17:05:20)

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  ><?php
function fibonacci($n) {
 
if ($n < 2) {
   
return $n;
 
}
 
return fibonacci($n - 2) + fibonacci($n - 1);
}
echo fibonacci
(40)."\n";
?>
de>
de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
1m43.579s
user  
1m36.905s
sys
0m0.349s
de>

PHP 5.4.6 (cli) (built: Sep 8 2012 23:49:53)

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
1m25.155s
user  
1m17.728s
sys
0m0.261s
de>

perl

This is perl 5, version 12, subversion 4 (v5.12.4) built for darwin-thread-multi-2level

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >sub fibonacci {
 
my $n = shift;
 
if ($n < 2) {
   
return $n;
 
}
 
return fibonacci($n - 2) + fibonacci($n - 1);
}
print fibonacci(40), "\n";
de>
de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
2m53.937s
user  
2m41.259s
sys
0m0.592s
de>

ruby 1.8.x

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >def fibonacci(n)
 
if n < 2
   
return n
 
end
 
return fibonacci(n - 2) + fibonacci(n - 1)
end

puts fibonacci
(40)
de>

ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]

de style="line-height: 22.75px; box-sizing: border-box; margin: 0px; padding: 0px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; word-wrap: break-word; font-size: inherit; color: inherit; border-radius: 4px; border: 0px; background-color: transparent;"  >102334155

real  
3m59.076s
user  
3m35.135s
sys
0m0.833s
de>

Conclusion

  • go is awsome!
  • nodejs is FAST, v0.8+ is FASTER.
  • luajit 2X faster than nodejs@0.6.x, Shocking.
  • ruby 1.9.x faster than lua.

Comments

blog comments powered by Disqus
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值