- 论坛徽章:
- 49
|
发表于昨天(18:01)(2013-05-14 18:01) , 已有1026次阅读 ,共7个评论
目录:[ -]
最近Go1.1正式发布, 根据官方的说法, Go1.1性能比Go1.0提升基本有30%-40%, 有时更多(当然也有不明显的情况).
Go1.1的详细介绍: Go1.1新特性介绍(语言和库更完善/性能提高约30%).
这里是针对Go1.1和C语言的性能测试: 测试的重点是语言的性能, 当然也会受到标准库性能的影响.
测试环境
gcc和gc版本:
gcc -v
gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
go version
go version go1.1 linux/amd64
测试结果
$GOROOT/test/bench/shootout/timing.sh
fasta -n 25000000
gcc -m64 -O2 fasta.c 0.86u 0.00s 0.87r
gc fasta 0.85u 0.00s 0.86r
gc_B fasta 0.83u 0.00s 0.83r
reverse-complement < output-of-fasta-25000000
gcc -m64 -O2 reverse-complement.c 0.45u 0.05s 0.50r
gc reverse-complement 0.60u 0.05s 0.65r
gc_B reverse-complement 0.55u 0.04s 0.59r
nbody -n 50000000
gcc -m64 -O2 nbody.c -lm 5.51u 0.00s 5.52r
gc nbody 7.16u 0.00s 7.18r
gc_B nbody 7.12u 0.00s 7.14r
binary-tree 15 # too slow to use 20
gcc -m64 -O2 binary-tree.c -lm 0.31u 0.00s 0.31r
gc binary-tree 1.08u 0.00s 1.07r
gc binary-tree-freelist 0.15u 0.00s 0.15r
fannkuch 12
gcc -m64 -O2 fannkuch.c 26.45u 0.00s 26.54r
gc fannkuch 35.99u 0.00s 36.08r
gc fannkuch-parallel 73.40u 0.00s 18.58r
gc_B fannkuch 25.18u 0.00s 25.25r
regex-dna 100000
gcc -m64 -O2 regex-dna.c -lpcre 0.25u 0.00s 0.26r
gc regex-dna 1.65u 0.00s 1.66r
gc regex-dna-parallel 1.72u 0.01s 0.67r
gc_B regex-dna 1.64u 0.00s 1.65r
spectral-norm 5500
gcc -m64 -O2 spectral-norm.c -lm 9.63u 0.00s 9.66r
gc spectral-norm 9.63u 0.00s 9.66r
gc_B spectral-norm 9.63u 0.00s 9.66r
k-nucleotide 1000000
gcc -O2 k-nucleotide.c -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -lglib-2.0 2.62u 0.00s 2.63r
gc k-nucleotide 2.69u 0.01s 2.71r
gc k-nucleotide-parallel 3.02u 0.00s 0.97r
gc_B k-nucleotide 2.66u 0.01s 2.68r
mandelbrot 16000
gcc -m64 -O2 mandelbrot.c 20.95u 0.00s 21.01r
gc mandelbrot 23.73u 0.00s 23.79r
gc_B mandelbrot 23.72u 0.00s 23.79r
meteor 2098
gcc -m64 -O2 meteor-contest.c 0.05u 0.00s 0.05r
gc meteor-contest 0.06u 0.00s 0.07r
gc_B meteor-contest 0.06u 0.00s 0.06r
pidigits 10000
gcc -m64 -O2 pidigits.c -lgmp 0.77u 0.00s 0.77r
gc pidigits 1.45u 0.01s 1.44r
gc_B pidigits 1.45u 0.01s 1.43r
threadring 50000000
gcc -m64 -O2 threadring.c -lpthread 12.05u 261.20s 216.36r
gc threadring 6.61u 0.00s 6.63r
chameneos 6000000
gcc -m64 -O2 chameneosredux.c -lpthread 4.04u 21.08s 4.20r
gc chameneosredux 4.97u 0.00s 4.99r
测试结果说明
其中gc_B是开了-B选项, 选项的说明如下:
go tool 6g -h
usage: 6g [options] file.go...
-+ compiling runtime
-% debug non-static initializers
-A for bootstrapping, allow 'any' type
-B disable bounds checking
...
应该就是禁用了Go的slice下标越界检测等特性.
测试的结果显示Go的性能已经和C语言已经非常接近了, 有极个别的甚至比C还好(binary-tree).
根据$GOROOT/test/bench/shootout/timing.log的数据, gccgo 的优化应该更好一点.
不过gccgo的标准库比gc性能可能要差一些(因此有些测试性能比gc差一些).
我电脑没有安装gccgo, 因此只有gcc/gc/gc_B三个测试结果.
关于 BenchmarksGame 的测试差异http://benchmarksgame.alioth.debian.org/u64q/go.php
BenchmarksGame的测试结果中, 有几个Go的性能很差:
Benchmark Time Memory Code
fasta 3× 3× ±
spectral-norm 4× 3× ±
binary-trees 13× 4× ±
regex-dna 26× ± 1/4
其中 spectral-norm 和 binary-trees 的 C 版本都开了 #pragma omp 优化(这已经不是C语言级别的比较了).
而 Go 的 binary-trees 启动了很多 goroutine, Go并发的版本和C的非并发版本比较肯定也是不合理的.
其中regex的测试主要是Go的regex标准库和C的高度优化的pcre比较. 目前Go的regex库还有待进一步的优化.
关于其他的各个程序, 实现和$GOROOT/test/bench/shootout都是有一定的差异的.
官方的测试结论http://go.googlecode.com/hg/test/bench/shootout/timing.log:
# Sep 26, 2012
# 64-bit ints, plus significantly better floating-point code.
# Interesting details:
# Generally something in the 0-10% slower range, some (binary tree) more
# Floating-point noticeably faster:
# nbody -25%
# mandelbrot -37% relative to Go 1.
# Other:
# regex-dna +47%
Go已经和C差距在10%以内, 有特殊场景性能甚至更好.
本文来自ChinaUnix新闻频道,如果查看原文请点:http://news.chinaunix.net/opensource/2013/0515/2764818.shtml
|
|