The Computer Language
24.04 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 4.00 19,652 1260 15.86
Rust #4 7.10 19,652 1026 27.94
Rust #5 7.88 19,784 1023 30.85
Swift 33.85 19,660 457 33.85
Swift #3 8.58 19,660 1103 33.96
Rust #2 18.53 19,780 1198 73.32
n-body
source secs mem gz cpu secs
Rust #9 2.20 19,660 1881 2.20
Rust #7 3.13 19,660 1759 3.13
Rust #2 3.92 19,660 1809 3.92
Rust #6 3.95 19,788 1796 3.95
Rust #8 4.51 19,788 1774 4.50
Rust #5 5.06 19,788 2224 5.06
Rust #4 5.21 19,660 1810 5.21
Swift #4 5.49 19,680 1361 5.49
Rust 5.51 19,660 1483 5.51
Swift #5 5.51 19,812 1372 5.51
Swift #7 5.52 19,684 1333 5.52
Rust #3 5.60 19,656 1546 5.60
Swift #6 5.97 19,680 1200 5.97
Swift #8 5.99 19,808 1688 5.99
Swift #2 9.55 19,684 1198 9.55
Swift #3 202.89 19,680 1210 202.89
Swift #9 287.28 19,684 1532 287.27
spectral-norm
source secs mem gz cpu secs
Rust #2 0.72 19,668 1117 2.58
Rust 0.74 19,668 1262 2.60
Rust #3 0.79 19,796 1060 2.83
Rust #6 0.72 19,668 1132 2.84
Rust #4 0.72 19,796 823 2.85
Rust #7 0.72 19,796 938 2.85
Rust #5 0.72 19,668 1062 2.85
Swift 5.32 19,684 444 5.32
Swift #3 1.43 19,684 607 5.69
mandelbrot
source secs mem gz cpu secs
Rust #4 0.96 33,280 1301 3.78
Rust #6 1.07 34,048 1338 4.20
Rust #8 1.06 33,280 770 4.21
Rust #7 1.06 33,280 763 4.21
Rust #5 1.12 33,920 725 4.40
Rust #3 1.14 19,656 1013 4.51
Swift #7 1.34 47,104 1147 5.30
Swift #6 1.45 50,176 1147 5.73
Rust 1.83 39,296 874 7.20
Swift 26.40 19,680 400 26.40
Swift #5 7.21 43,520 665 26.95
Swift #3   Bad Output  
pidigits
source secs mem gz cpu secs
Rust #4 0.71 19,660 804 0.71
Rust 0.88 19,660 1426 0.88
Rust #3 0.88 19,660 1373 0.88
Rust #2 0.88 19,660 1312 0.88
Swift #2 0.88 19,684 606 0.88
regex-redux
source secs mem gz cpu secs
Rust #6 1.19 153,584 994 1.44
Rust #5 1.28 202,584 777 1.52
Rust 1.30 154,416 811 1.52
Rust #4 1.30 199,540 771 1.54
Rust #3 1.31 202,684 726 1.56
Rust #2 1.34 153,896 707 1.58
Rust #7 0.78 150,272 2464 1.99
Swift #2 41.76 684,640 678 41.75
Swift 24.13 889,972 721 42.70
Swift #4 20.41 1,060,208 751 44.32
fasta
source secs mem gz cpu secs
Rust #7 0.76 19,664 2533 1.51
Rust #3 2.00 19,656 1235 2.00
Rust #8 0.92 19,784 1952 3.10
Rust #2 0.91 19,656 1910 3.29
Rust #5 0.91 19,656 1963 3.30
Rust #4 3.45 123,784 944 3.45
Rust #6 3.48 123,784 959 3.48
Swift #2 2.18 19,680 1952 3.83
Rust 4.52 19,656 1240 4.52
Swift 5.15 19,676 1533 5.15
Swift #3 2.14 29,584 2097 5.26
k-nucleotide
source secs mem gz cpu secs
Rust #7 2.86 134,084 1585 9.12
Rust #8 3.68 137,580 1549 10.41
Rust #6 2.90 159,464 1697 10.51
Rust #5 3.91 137,764 1745 11.86
Rust #2 6.10 139,388 1350 16.32
Rust #9 6.77 135,684 1850 18.07
Rust #4 6.70 137,288 1755 18.12
Swift #2 14.51 259,048 1373 55.29
Rust 21.62 157,080 1086 64.67
Swift   Make Error  
reverse-complement
source secs mem gz cpu secs
Rust 0.52 498,816 2762 0.83
Rust #2 0.85 995,200 1332 1.50
Rust #3 0.87 995,072 1105 1.58
Swift 1.88 796,840 1293 2.30
binary-trees
source secs mem gz cpu secs
Rust #5 1.08 198,528 771 3.82
Rust #2 1.22 199,676 729 4.29
Rust #4 1.29 189,052 765 4.67
Rust #3 1.39 198,860 762 5.04
Rust 2.04 133,120 760 7.21
Swift #5 13.79 736,000 813 40.99
Swift #3 13.33 705,408 868 43.00
Swift #2 13.28 705,280 822 43.28
Swift 20.15 735,488 720 59.68
Swift #4 19.49 705,536 772 62.34
Swift #9   Make Error  
Swift

Swift version 5.10
(swift-5.10-RELEASE)

Rust

1.76.0
(07dca489a
2024-02-04)
LLVM version: 17.0.6