The Computer Language
Benchmarks Game

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

fannkuch-redux
source secs mem gz busy cpu load
Swift 10.11 8,048 1097 40.10 98% 100% 99% 100%
Rust 10.62 944 1016 41.73 100% 93% 100% 100%
pidigits
source secs mem gz busy cpu load
Swift 1.75 8,976 600 1.79 1% 1% 0% 100%
Rust 1.75 3,052 1366 1.78 1% 0% 1% 100%
reverse-complement
source secs mem gz busy cpu load
Swift 3.82 714,868 1286 4.57 81% 3% 36% 0%
Rust 2.21 995,040 1871 3.10 1% 48% 24% 67%
mandelbrot
source secs mem gz busy cpu load
Swift 3.20 39,384 1138 12.70 100% 99% 99% 99%
Rust 1.70 30,492 1332 6.70 98% 98% 98% 100%
spectral-norm
source secs mem gz busy cpu load
Swift 3.96 7,996 601 15.79 100% 99% 100% 100%
Rust 1.97 2,196 1126 7.87 100% 100% 99% 99%
fasta
source secs mem gz busy cpu load
Swift 3.22 8,792 1945 4.82 36% 29% 43% 41%
Rust 1.51 2,044 1906 4.60 74% 83% 73% 74%
n-body
source secs mem gz busy cpu load
Swift 22.03 12,268 1355 22.25 0% 0% 100% 1%
Rust 6.07 944 1753 6.14 0% 0% 100% 1%
k-nucleotide
source secs mem gz busy cpu load
Swift 21.77 257,384 1367 82.66 94% 97% 94% 95%
Rust 5.40 135,184 1749 17.13 60% 92% 69% 96%
binary-trees
source secs mem gz busy cpu load
Swift 44.93 733,728 714 133.24 78% 70% 74% 75%
Rust 3.33 199,664 721 12.08 87% 100% 88% 87%
regex-redux
source secs mem gz busy cpu load
Swift 43.98 880,444 715 78.94 9% 57% 29% 85%
Rust 2.10 153,076 986 3.14 30% 17% 83% 19%
Swift

Swift version 5.1.1-dev (LLVM b47beb8a70, Swift 7e43e9bcfd)
Target: x86_64-unknown-linux-gnu

Rust

rustc 1.39.0 (4560ea788 2019-11-04)
LLVM version: 9.0