The Computer Language
23.02 Benchmarks Game

Swift versus Rust fastest performance

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.51 11,036 1253 13.93
Rust #4 7.21 10,932 1020 28.34
Rust #5 7.77 10,932 1016 30.49
Swift #3 8.24 11,220 1097 32.62
Swift 34.60 11,220 451 34.59
Rust #2 17.99 11,036 1191 70.95
n-body
source secs mem gz cpu secs
Rust #9 2.81 11,068 1874 2.81
Rust #7 3.27 11,068 1753 3.27
Rust #6 3.92 11,068 1790 3.92
Swift #5 5.44 14,780 1365 5.43
Swift #7 5.44 14,792 1326 5.44
Swift #4 5.45 14,780 1355 5.45
Rust #3 5.63 11,068 1540 5.63
Rust 5.63 11,068 1480 5.63
Swift #8 5.92 14,820 1681 5.92
Swift #6 5.93 11,340 1194 5.93
Rust #2 5.98 11,068 1805 5.98
Rust #8 6.01 11,068 1767 6.01
Rust #5 6.12 11,068 2220 6.11
Rust #4 6.20 11,068 1803 6.20
Swift #3 8.06 11,340 1204 8.06
Swift #2 9.12 11,340 1192 9.12
Swift #9 285.30 14,892 1526 285.29
spectral-norm
source secs mem gz cpu secs
Rust #6 0.71 11,124 1126 2.84
Rust #7 0.72 11,128 932 2.84
Rust #5 0.72 11,124 1055 2.84
Rust #4 0.72 11,124 817 2.84
Rust #2 0.72 11,124 1110 2.85
Rust 0.72 11,124 1254 2.85
Rust #3 0.78 11,124 1053 3.07
Swift 5.32 14,944 438 5.32
Swift #3 1.43 11,344 601 5.68
mandelbrot
source secs mem gz cpu secs
Rust #4 1.01 32,380 1295 3.99
Rust #6 1.06 34,120 1332 4.18
Rust #5 1.12 33,868 719 4.41
Rust #3 1.15 13,452 1007 4.58
Swift #7 1.40 46,628 1140 5.57
Rust #7 1.42 32,124 757 5.64
Rust #8 1.42 32,176 763 5.64
Swift #6 1.42 49,544 1141 5.64
Rust 2.05 38,724 868 8.09
Swift 25.99 11,340 394 25.98
Swift #5 7.29 43,012 659 26.91
Swift #3   Bad Output  
pidigits
source secs mem gz cpu secs
Rust #4 0.71 11,068 799 0.71
Rust #2 0.88 11,068 1306 0.88
Rust #3 0.88 11,068 1366 0.88
Swift #2 0.88 11,344 600 0.88
Rust 0.89 11,068 1420 0.88
regex-redux
source secs mem gz cpu secs
Rust #6 1.34 152,724 986 1.80
Rust #5 1.40 204,604 771 1.82
Rust #4 1.43 204,656 765 1.85
Rust 1.46 153,312 804 1.87
Rust #3 1.42 205,228 719 1.88
Rust #2 1.50 153,320 701 1.90
Rust #7 0.78 149,524 2458 1.99
Swift #2 34.87 683,772 671 34.85
Swift 18.89 883,576 715 35.94
Swift #4 18.76 962,572 745 36.82
fasta
source secs mem gz cpu secs
Rust #7 0.76 11,068 2529 1.52
Rust #3 2.00 11,036 1233 2.00
Swift #2 2.25 11,340 1945 3.05
Rust #5 0.90 11,060 1961 3.08
Rust #2 0.90 11,068 1906 3.16
Rust #4 3.46 123,660 939 3.46
Rust #6 3.50 123,660 955 3.50
Rust #8 0.92 11,068 1946 3.50
Swift 4.51 11,340 1526 4.51
Swift #3 1.39 27,800 2090 4.51
Rust 4.52 11,036 1237 4.52
k-nucleotide
source secs mem gz cpu secs
Rust #7 2.88 133,236 1578 9.14
Rust #8 3.56 137,632 1543 10.34
Rust #6 2.88 158,788 1691 10.48
Rust #5 4.08 137,648 1739 11.99
Rust #2 6.30 137,548 1347 16.69
Rust #9 6.54 136,008 1841 17.81
Rust #4 6.95 136,744 1749 18.88
Swift #2 13.63 258,044 1367 52.21
Rust 21.93 155,840 1078 65.94
Swift   Make Error  
reverse-complement
source secs mem gz cpu secs
Rust 0.47 498,844 3040 0.77
Rust #2 0.80 995,004 1330 1.45
Rust #3 0.81 995,004 1097 1.50
Swift 1.85 795,972 1286 2.30
binary-trees
source secs mem gz cpu secs
Rust #5 1.08 198,984 765 3.82
Rust #2 1.19 200,532 721 4.27
Rust #4 1.28 198,772 756 4.62
Rust #3 1.36 198,464 754 4.93
Rust 2.10 132,828 751 7.39
Swift #5 13.35 735,440 806 39.79
Swift #3 13.06 704,876 862 41.74
Swift #2 13.04 704,780 816 42.00
Swift 19.62 734,844 714 58.29
Swift #4 18.96 704,904 765 60.01
Swift #9   Make Error  
Swift

Swift version 5.8-dev
(LLVM 08f7fecaf6cedb8,
Swift 24fe6ae8532db5d)

Rust

1.67.0
(fc594f156
2023-01-24)
LLVM version: 15.0.6