golang编程语言和java的性能对比
这篇文章主要介绍了golang、java性能的对比,需要的朋友可以参考下!
1.先说Go吧,因为我个人最近正在用,感觉很不错
package main import "fmt" func main(){ fmt.Println(fibonacci(34)) } func fibonacci(i int) int{ if(i<2){ return i; } return fibonacci(i-2) + fibonacci(i-1); }
先用 Go1.7看看:
复制代码
代码如下:
qiangjian@localhost:/works/learnCPP$ go version && time go build fib.go && time ./fib
go version go1.7.5 darwin/amd64real 0m0.206s
user 0m0.165s
sys 0m0.059s
real 0m0.052s
user 0m0.045s
sys 0m0.004s
然后,再看看1.8的:
代码如下:
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
性能还行, Compile时间和c++/go比就太low了。
相关推荐
GoatSucker 2020-11-23
CoderToy 2020-11-16
蛰脚踝的天蝎 2020-11-10
ZGCdemo 2020-11-09
86193952 2020-10-27
Lzs 2020-10-23
hjr 2020-10-21
HELLOBOY 2020-10-21
qidiantianxia 2020-10-21
cmsmdn 2020-10-21
myspace 2020-10-21
笑面依旧 2020-10-21
专注前端开发 2020-10-21
技术之博大精深 2020-10-16
zhushenghan 2020-11-09
风雨断肠人 2020-10-13
xuguiyi00 2020-11-04
sichenglain 2020-10-27