代码如下:
qiangjian@localhost:/works/learnCPP$ go18 version && time go18 build fib.go && time ./fib
go version go1.8 darwin/amd64real 0m0.204s
user 0m0.153s
sys 0m0.062s
real 0m0.051s
user 0m0.045s
sys 0m0.003s
感觉看不出差异,但官方1.8在GC、Compile等方面优化提升了20%,可能是这demo太简单了吧。
2、再来写Java,虽然它很火,感觉太臃肿了
class Fib{
public static void main(String[] args){
System.out.println(fibonacci(34));
}
static int fibonacci( int i){
if(i<2) return i;
return fibonacci(i-2) + fibonacci(i-1);
}
}
编译、运行的结果是:
qiangjian@localhost:/works/learnCPP$ java -version && time javac Fib.java && time java Fib
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
real 0m0.952s
user 0m1.302s
sys 0m0.144s
real 0m0.150s
user 0m0.123s
sys 0m0.025s