我一直在尝试使用gc和gccgo,并且遇到一些奇怪的行为。为什么使用gccgo构建的二进制文件更小(其他区别?)
使用program我曾经写过测试一些定理,我得到了这些结果:(我删除了readablitity不必要的信息)
$ time go build -compiler gc -o checkprog_gc checkprog.go (x 3)
go build <...> 0.13s user 0.02s system 100% cpu 0.149 total
go build <...> 0.13s user 0.01s system 99% cpu 0.148 total
go build <...> 0.14s user 0.03s system 100% cpu 0.162 total
--> average: 0.13s user 0.02s system 100% cpu 0.153 total
$ time go build -compiler gccgo -o checkprog_gccgo checkprog.go (x 3)
go build <...> 0.10s user 0.03s system 96% cpu 0.135 total
go build <...> 0.12s user 0.01s system 96% cpu 0.131 total
go build <...> 0.10s user 0.01s system 92% cpu 0.123 total
--> average: 0.11s user 0.02s system 95% cpu 0.130 total
$ strip -s -o checkprog_gc_stripped checkprog_gc
$ strip -s -o checkprog_gccgo_stripped checkprog_gccgo
$ ls -l
1834504 checkprog_gc*
1336992 checkprog_gc_stripped*
35072 checkprog_gccgo*
24192 checkprog_gccgo_stripped*
$ time ./checkprog_gc
./checkprog_gc 6.68s user 0.01s system 100% cpu 6.674 total
./checkprog_gc 6.75s user 0.01s system 100% cpu 6.741 total
./checkprog_gc 6.66s user 0.00s system 100% cpu 6.643 total
--> average: 6.70s user 0.01s system 100% cpu 6.686 total
$ time ./checkprog_gccgo
./checkprog_gccgo 10.95s user 0.02s system 100% cpu 10.949 total
./checkprog_gccgo 10.98s user 0.01s system 100% cpu 10.964 total
./checkprog_gccgo 10.94s user 0.01s system 100% cpu 10.929 total
--> average 10.96s user 0.01s system 100% cpu 10.947 total
我可以看到下面的模式:内置
- 二进制与
gccgo
的大小从根本上小(剥离无助于改变这种差异)与gc
内置 - 二进制文件可以更快地执行
- 它需要更多的时间来建立与
gccgo
比gc
我还测试了一些其他的围棋程序(而不是广泛地),他们都表现出相同的行为。
这似乎矛盾的时候,this answer状态:
简而言之:gccgo:更多的优化,更多的处理器。
我认为更多的优化意味着更快的二进制文件,而需要更多的时间来编译......
是什么原因这三种模式?
很可能是因为它们链接到'libgo'。 'ldd'或'readelf'会告诉你(如果你在Linux系统上)。 – kostix 2014-11-21 18:06:56