The Computer Language
25.01 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
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
* Rust #6 3.81 4,137 1260 15.16—15.32
Rust #4 6.90 4,141 1026 27.12
Rust #5 7.47 3,985 1023 29.34
* Swift #3 8.22 13,808 1103 32.51—32.60
Swift #8 34.68 13,476 470 34.69—34.77
Rust #2 9.16 3,985 1198 35.93
n-body
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
* Rust #9 2.19 3,195 1881 1.61—3.97
* Rust #7 3.24 2,937 1759 3.24
Rust #3 3.46 3,023 1774 3.46
Rust #2 3.65 3,019 1809 3.65
* Rust #6 4.36 3,019 1796 4.10—5.43
* Rust #5 5.02 3,027 2224 5.02
Rust #4 5.13 3,019 1810 4.83—6.12
* Swift #3 5.46 25,002 1688 5.45—5.53
* Swift #4 5.49 25,010 1361 5.49
* Swift #5 5.52 25,010 1372 5.51—5.54
* Swift #7 5.53 25,010 1333 5.52
Rust 5.52 3,019 1483 5.56—5.66
Swift #6 5.81 12,947 1213 5.79—5.86
Swift #8 6.66 12,808 1285 6.66
Swift 7.89 12,808 1210 7.88
Swift #9 287.49 24,867 1532 287.52—287.99
spectral-norm
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
* Rust #6 0.72 4,293 1132 2.85
Rust #4 0.72 4,014 823 2.85
* Rust #5 0.72 3,981 1062 2.85
* Rust 0.72 4,276 1262 2.86
* Rust #2 0.73 4,264 1117 2.86
* Rust #3 0.74 4,010 1060 2.94
Swift #8 5.36 24,936 411 5.35
Swift #3 1.45 13,705 607 5.71
* Rust #7   Empty  
mandelbrot
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
* Rust #4 0.95 35,955 1301 3.78
* Rust #6 1.08 36,385 1338 4.22
Rust #2 1.10 36,016 770 4.34
Rust #5 1.12 36,549 725 4.38
Rust #7 1.11 35,934 763 4.38
Rust #3 1.15 14,008 1013 4.57
* Swift #7 1.35 57,856 1147 5.30
* Swift #6 1.48 60,969 1147 5.78
Rust 2.03 42,541 874 7.90
Swift #8 25.63 12,841 426 25.62
Swift 26.55 12,853 400 26.54
Swift #5 7.28 49,291 665 27.12
* Swift #3   Bad Output  
fasta
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
* Rust #7 0.78 4,866 2533 1.55
Rust #3 1.98 2,933 1235 1.98
Rust #9 0.94 5,362 1952 3.22—3.29
Rust #5 0.94 5,505 1963 3.34—3.43
Rust #2 0.94 5,550 1910 3.45—3.49
Rust #6 3.48 128,033 959 3.48
Rust #4 3.48 128,160 944 3.48
* Swift #2 2.24 13,767 1952 4.81—5.86
Rust 4.49 2,990 1240 4.51—4.55
* Swift #3 2.20 39,313 2097 5.37
* Swift 5.43 12,640 1533 5.43—5.46
Swift #8 18.86 12,837 828 18.86—18.91
k-nucleotide
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
Rust #7 2.61 139,071 1585 8.25—8.47
Rust #3 3.24 141,701 1549 9.49—9.79
Rust #6 2.81 165,057 1697 10.18—10.41
Rust #5 3.82 143,118 1745 11.26—11.52
Rust #2 6.05 143,139 1350 15.56—16.02
Rust #9 6.58 140,845 1850 17.43—18.35
Rust #4 6.76 142,778 1755 18.85—19.78
* Swift #2 14.46 273,932 1373 55.17—55.42
Rust 21.38 159,539 1086 65.42—66.28
Swift #8 167.99 904,810 658 176.45—187.83
Swift #7 225.53 649,970 607 232.57—241.98
Swift   Empty  
reverse-complement
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
* Rust 0.54 513,090 2762 0.85
Rust #2 0.99 1,022,960 1332 1.63
Rust #3 1.00 1,022,190 1105 1.73
* Swift 1.97 825,594 1293 2.41
binary-trees
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
Rust #5 1.10 137,413 771 3.96—4.09
Rust #2 1.21 141,509 729 4.32—4.37
Rust #4 1.38 171,651 765 5.04—5.11
Rust #3 1.40 162,599 762 5.05—5.11
Rust 2.07 137,667 760 7.21—7.27
Swift 18.32 763,609 720 54.27—54.37
Swift #8 54.91 416,625 567 54.99—57.09
Swift #4 17.69 733,131 772 55.74—57.55
Swift #5 18.99 764,781 813 56.24—57.93
Swift #2 18.36 733,131 822 58.70—64.46
Swift #3 18.24 733,000 868 58.66—59.10
* Swift #9   Empty  
pidigits
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
Rust #4 0.72 3,994 804 0.72
* Rust 0.75 4,239 1426 0.75
* Rust #2 0.75 4,243 1312 0.75
* Rust #3 0.75 4,481 1373 0.75
* Swift #2 0.76 14,238 606 0.75
regex-redux
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
Rust #6 1.18 160,154 994 1.43
Rust #5 1.34 210,186 777 1.58
Rust 1.33 160,023 811 1.57—1.60
Rust #4 1.35 206,840 771 1.60
Rust #3 1.36 210,850 726 1.59—1.64
Rust #2 1.39 160,625 707 1.64
* Rust #7 0.79 155,496 2464 2.01
Swift #2 38.81 710,750 678 38.85—39.04
Swift 23.39 922,284 721 39.78—39.90
Swift #4 18.22 1,099,583 751 41.25—41.56
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