The Computer Language
Benchmarks Game

Go versus C++ g++ fastest programs

Back in April 2010, Russ Cox charitably suggested that only fannkuch-redux, fasta, k-nucleotide, mandlebrot, nbody, reverse-complement and spectral-norm were close to fair comparisons. As someone who implemented programming languages, his interest was "measuring the quality of the generated code when both compilers are presented with what amounts to the same program."

Differences in approach - to memory management, parallel programming, regex, arbitrary precision arithmetic, implementation technique - don't fit in that kind-of fair comparison — but we still have to deal with them.

These are only the fastest programs. There may be additional measurements for programs which seem more-like a fair comparison to you. Always look at the source code.

pidigits
source secs mem gz busy cpu load
Go 2.10 8,448 603 2.17 1% 48% 55% 0%
C++ g++ 1.89 4,552 513 1.92 1% 100% 1% 0%
fasta
source secs mem gz busy cpu load
Go 2.08 3,560 1358 5.61 80% 37% 76% 78%
C++ g++ 1.46 2,216 2711 4.40 75% 75% 76% 75%
fannkuch-redux
source secs mem gz busy cpu load
Go 17.56 1,524 900 70.00 100% 100% 100% 100%
C++ g++ 10.69 1,896 980 42.28 100% 100% 96% 100%
spectral-norm
source secs mem gz busy cpu load
Go 3.94 2,740 548 15.74 100% 100% 100% 100%
C++ g++ 1.98 2,268 1044 7.89 100% 99% 99% 99%
reverse-complement
source secs mem gz busy cpu load
Go 3.83 1,782,940 1338 6.67 21% 74% 16% 62%
C++ g++ 1.61 996,244 1226 2.76 25% 24% 96% 27%
n-body
source secs mem gz busy cpu load
Go 21.25 1,588 1310 21.48 0% 1% 100% 0%
C++ g++ 7.92 1,116 1773 8.51 6% 1% 1% 100%
k-nucleotide
source secs mem gz busy cpu load
Go 11.77 160,184 1607 44.52 94% 98% 94% 92%
C++ g++ 3.81 156,348 1624 11.78 70% 70% 73% 96%
mandelbrot
source secs mem gz busy cpu load
Go 5.47 31,088 905 21.77 100% 99% 99% 99%
C++ g++ 1.51 25,828 1791 6.03 100% 100% 100% 100%
binary-trees
source secs mem gz busy cpu load
Go 25.17 361,152 1005 86.86 87% 89% 86% 84%
C++ g++ 3.92 114,136 809 12.90 82% 75% 73% 98%
regex-redux
source secs mem gz busy cpu load
Go 29.82 428,224 802 62.65 48% 45% 52% 65%
C++ g++ 1.83 203,932 1315 4.44 44% 99% 48% 51%
Go

go version go1.13 linux/amd64

C++ g++

g++ (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008