The Computer Language
Benchmarks Game

Swift versus Go 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.

binary-trees
source secs mem gz busy cpu load
Swift 5.14 193,592 1001 14.38 59% 61% 59% 100%
Go 27.36 498,196 950 107.79 98% 99% 99% 98%
fannkuch-redux
source secs mem gz busy cpu load
Swift 9.97 7,428 1097 39.55 100% 98% 100% 98%
Go 17.24 1,432 900 68.76 100% 100% 100% 100%
mandelbrot
source secs mem gz busy cpu load
Swift 3.23 38,984 1138 12.84 99% 100% 99% 99%
Go 5.48 30,820 894 21.79 100% 99% 99% 99%
pidigits
source secs mem gz busy cpu load
Swift 1.75 8,612 600 1.78 0% 100% 1% 1%
Go 2.03 8,684 603 2.08 1% 1% 0% 100%
reverse-complement
source secs mem gz busy cpu load
Swift 3.73 789,268 1286 4.52 2% 81% 1% 38%
Go 3.99 824,856 611 4.24 6% 1% 1% 98%
spectral-norm
source secs mem gz busy cpu load
Swift 3.95 8,100 601 15.77 100% 100% 100% 100%
Go 3.94 2,136 548 15.71 99% 100% 100% 99%
n-body
source secs mem gz busy cpu load
Swift 22.04 19,004 1355 22.24 1% 0% 0% 100%
Go 21.06 1,432 1200 21.29 0% 0% 100% 1%
fasta
source secs mem gz busy cpu load
Swift 2.37 34,072 2090 7.11 45% 82% 88% 84%
Go 2.07 2,928 1358 5.84 83% 30% 83% 86%
regex-redux
source secs mem gz busy cpu load
Swift 42.62 887,168 715 74.41 75% 81% 0% 19%
Go 29.20 399,668 802 61.29 71% 55% 37% 47%
k-nucleotide
source secs mem gz busy cpu load
Swift 21.86 264,332 1367 82.77 93% 98% 95% 93%
Go 12.08 157,488 1607 45.40 93% 93% 97% 92%
Swift

Swift version 5.0-dev (LLVM f961e3dd74, Swift ff641d3965)
Target: x86_64-unknown-linux-gnu

Go

go version go1.12.4 linux/amd64