views:

1028

answers:

2

As we can see from The Computer Language Benchmarks Game:

  • go is in average 10x slower then C
  • go is 3x slower then Java !?

How it can be bearing in mind that go compiler produces native code for execution?
Immature compilers for go? Or there is some intrinsic problem with the go language?

EDIT:
Most answers deny intrinsic slowness of Go languge, the problem resides in unmature compilers.
Therefore I've made some own tests to calculate Fibonacci numbers: Iterative algorithm runs in Go (freebsd,6g) with the same speed as in C (with O3 option). The dull recursive one runs in Go 2 times slower then in C (with -O3 option; with -O0 - the same). But I haven't seen 10x fall as in the Benchmarks Game.

Thanks a lot for answers!

+13  A: 

The 6g and 8g compilers are not particularly optimising, so the code they produce isn't particularly fast.

They're designed to run fast themselves and produce code that's OK (there is a bit of optimisation). gccgo uses GCC's existing optimisation passes, and might provide a more pointful comparison with C, but gccgo isn't feature-complete yet.

Benchmark figures are almost entirely about quality of implementation. They don't have a huge amount to do with the language as such, except to the extent that the implementation spends runtime supporting language features that the benchmark doesn't really need. In most compiled languages a sufficiently clever compiler could in theory strip out what isn't needed, but there comes a point where you're rigging the demo, since very few real users of the language would write programs that didn't use that feature. Moving things out of the way without removing them entirely (e.g. predicting virtual call destinations in JIT-compiled Java) starts to get tricky.

FWIW, my own very trivial test with Go when I was taking a look at it (a loop of integer addition, basically), gccgo produced code towards the fast end of the range between gcc -O0 and gcc -O2 for equivalent C. Go isn't inherently slow, but the compilers don't do everything, yet. Hardly surprising for a language that's 10 minutes old.

Steve Jessop
Moreover, it may be that Go programs in The Computer Language Benchmarks Game are not that optimized as C and Java ones are.
el.pescado
What about between gcc -O0 and gcc -O3 ? Is there even the intention that the compilers will "do everything" ?
igouy
@igouy: well, I'm pretty sure that there's an intention gccgo will do garbage collection, which currently it doesn't. There are still some features to go into the g compilers too, for instance they don't currently use host threads particularly well (specifically, the goroutine scheduler isn't pre-emptive). Beyond that, I don't know Google's plans, whether the g compilers will ever be fiercely optimising, or if only gccgo will.
Steve Jessop
+3  A: 

In the next release of the Go FAQ, something similar to the following should appear.

Performance

Why does Go perform badly on benchmark X?

One of Go's design goals is to approach the performance of C for comparable programs, yet on some benchmarks it does quite poorly, including several in test/bench. The slowest depend on libraries for which versions of comparable performance are not available in Go. For instance, pidigits depends on a multi-precision math package, and the C versions, unlike Go's, use GMP (which is written in optimized assembler). Benchmarks that depend on regular expressions (regex-dna, for instance) are essentially comparing Go's stopgap regexp package to mature, highly optimized regular expression libraries like PCRE.

Benchmark games are won by extensive tuning and the Go versions of most of the benchmarks need attention. If you measure comparable C and Go programs (reverse-complement is one example), you'll see the two languages are much closer in raw performance than this suite would indicate.

Still, there is room for improvement. The compilers are good but could be better, many libraries need major performance work, and the garbage collector isn't fast enough yet (even if it were, taking care not to generate unnecessary garbage can have a huge effect).

And here's some more details on The Computer Benchmarks Game from a recent mailing list thread.

Garbage collection and performance in gccgo (1)

Garbage collection and performance in gccgo (2)

It's important to note that the Computer Benchmarks Game is just a game. People with experience in performance measurement and capacity planning carefully match like with like over realistic and actual workloads; they don't play games.

peterSO
And here some details from that same thread that you have excluded - http://groups.google.com/group/golang-nuts/msg/2e568d2888970308
igouy
It's important to note that "benchmarks are a crock" - not just the benchmarks published as the benchmarks game - http://shootout.alioth.debian.org/flawed-benchmarks.php
igouy