The Computer Language
24.11 Benchmarks Game

Rust versus Swift fastest performance

How the programs are written matters! Always look at the source code.

If the fastest programs are * hand-written vector instructions, does the host language matter? You might be more interested in the less optimised programs — more seconds, less gz source code.

fannkuch-redux
source secs mem gz cpu secs
* Rust #6 3.86 19,684 1260 15.17
Rust #4 6.92 19,684 1026 27.13
Rust #5 7.45 19,684 1023 29.32
* Swift #3 8.32 19,440 1103 32.99
Swift #8 35.13 19,444 470 35.12
Rust #2 9.15 19,684 1198 35.91
n-body
source secs mem gz cpu secs
* Rust #9 2.19 19,624 1881 2.19
* Rust #7 3.23 19,624 1759 3.23
Rust #3 3.46 19,624 1774 3.45
Rust #2 3.64 19,624 1809 3.64
* Rust #6 4.36 19,624 1796 4.35
* Rust #5 5.01 19,624 2224 5.01
Rust #4 5.11 19,624 1810 5.11
* Swift #3 5.43 19,440 1688 5.43
* Swift #4 5.46 19,440 1361 5.46
* Swift #5 5.49 19,440 1372 5.49
* Swift #7 5.50 19,440 1333 5.50
Rust 5.52 19,624 1483 5.52
Swift #6 5.78 19,440 1213 5.78
Swift #8 6.65 19,440 1285 6.65
Swift 7.85 19,440 1210 7.85
Swift #9 288.23 19,440 1532 288.20
spectral-norm
source secs mem gz cpu secs
* Rust 0.72 19,632 1262 2.80
* Rust #2 0.72 19,632 1117 2.80
Rust #4 0.72 19,632 823 2.85
* Rust #5 0.72 19,632 1062 2.85
* Rust #6 0.72 19,632 1132 2.85
* Rust #3 0.74 19,632 1060 2.86
Swift #8 5.33 19,568 411 5.33
Swift #3 1.43 19,440 607 5.69
* Rust #7   Make Error  
mandelbrot
source secs mem gz cpu secs
* Rust #4 0.95 33,392 1301 3.77
* Rust #6 1.07 34,152 1338 4.20
Rust #2 1.09 33,384 770 4.33
Rust #7 1.10 33,380 763 4.37
Rust #5 1.11 33,956 725 4.37
Rust #3 1.14 19,624 1013 4.54
* Swift #7 1.38 49,024 1147 5.49
* Swift #6 1.46 51,840 1147 5.78
Rust 2.00 39,404 874 7.88
Swift #8 25.59 19,492 426 25.59
Swift 26.45 19,440 400 26.45
Swift #5 7.25 43,648 665 27.03
* Swift #3   Bad Output  
fasta
source secs mem gz cpu secs
* Rust #7 0.77 19,624 2533 1.54
Rust #3 1.98 19,624 1235 1.98
Rust #9 0.94 19,624 1952 3.22
Rust #5 0.93 19,624 1963 3.34
Rust #2 0.92 19,624 1910 3.40
Rust #6 3.46 123,848 959 3.46
Rust #4 3.47 123,848 944 3.46
* Swift #2 2.11 19,440 1952 3.76
Rust 4.25 19,624 1240 4.25
* Swift 5.15 19,440 1533 5.14
* Swift #3 2.18 31,248 2097 5.40
Swift #8 18.86 19,972 828 18.86
k-nucleotide
source secs mem gz cpu secs
Rust #7 2.67 133,824 1585 8.21
Rust #3 3.21 137,564 1549 9.51
Rust #6 2.80 159,764 1697 10.03
Rust #5 3.82 137,924 1745 11.17
Rust #2 5.87 138,292 1350 15.32
Rust #9 6.63 136,168 1850 17.12
Rust #4 6.73 137,308 1755 18.72
* Swift #2 14.54 260,820 1373 55.20
Rust 21.46 157,492 1086 66.75
Swift #8 181.50 627,328 658 180.87
Swift #7 233.16 627,092 607 232.52
Swift   Make Error  
reverse-complement
source secs mem gz cpu secs
* Rust 0.53 498,952 2762 0.84
Rust #2 0.95 995,220 1332 1.58
Rust #3 0.97 995,156 1105 1.69
* Swift 1.95 798,228 1293 2.39
binary-trees
source secs mem gz cpu secs
Rust #5 1.09 198,720 771 3.84
Rust #2 1.19 199,796 729 4.21
Rust #3 1.39 189,928 762 5.00
Rust #4 1.39 199,084 765 5.01
Rust 2.04 132,952 760 7.26
Swift 18.28 737,152 720 54.20
Swift #8 54.90 402,048 567 54.89
Swift #4 17.49 707,456 772 55.84
Swift #5 18.89 738,048 813 56.25
Swift #2 18.29 707,456 822 58.16
Swift #3 18.18 707,584 868 58.24
* Swift #9   Make Error  
pidigits
source secs mem gz cpu secs
Rust #4 0.71 19,624 804 0.71
* Rust #3 0.74 19,624 1373 0.74
* Rust #2 0.74 19,624 1312 0.74
* Rust 0.74 19,624 1426 0.74
* Swift #2 0.75 19,440 606 0.75
regex-redux
source secs mem gz cpu secs
Rust #6 1.17 153,780 994 1.42
Rust 1.34 153,972 811 1.56
Rust #5 1.33 202,800 777 1.57
Rust #4 1.34 199,684 771 1.58
Rust #3 1.34 202,952 726 1.59
Rust #2 1.38 153,932 707 1.63
* Rust #7 0.78 148,924 2464 2.00
Swift #2 38.80 686,136 678 38.80
Swift 23.40 891,792 721 39.65
Swift #4 18.30 1,064,768 751 41.36
Rust

1.83.0
(90b35a623
2024-11-26)
LLVM version: 19.1.1

Swift

Swift version 6.0
(swift-6.0-RELEASE)
Target: x86_64-unknown-linux-gnu