The Computer Language
25.03 Benchmarks Game

Swift versus Go

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

If the fastest programs are flagged * possible hand-written vector instructions or "unsafe" or naked ffi, 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 cpu secs mem gz make
* Swift #3 8.20 32.45—32.61 13,722 1103 12.93
Go #3 8.36 33.35 3,846 975 5.31
Swift #8 34.68 34.68—34.74 13,484 470 12.33
Go #8 46.15 46.26—46.33 3,207 500 5.43
Go 12.27 49.09 4,903 906 5.41
Go #2 12.36 49.40 16,966 903 5.43
n-body      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* Swift #3 5.45 5.44—5.48 24,928 1688 14.75
* Swift #4 5.48 5.49 24,846 1361 13.94
* Swift #5 5.52 5.50—5.55 24,928 1372 12.83
* Swift #7 5.53 5.52 24,932 1333 13.80
Swift #6 5.82 5.81 12,956 1213 12.42
Go #3 6.39 6.41 3,191 1207 5.43
Swift #8 6.66 6.56—6.95 12,804 1285 12.85
Go 7.02 7.09—7.27 3,228 1316 5.36
Go #2 7.04 7.06 3,203 1222 5.35
Swift 7.89 7.88 12,812 1210 12.10
Go #8 9.60 9.64 3,191 1224 5.47
Swift #9 287.37 287.38—288.05 24,793 1532 13.91
spectral-norm      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
Swift #8 5.36 5.35 24,859 411 14.09
Go #8 5.34 5.36 3,838 429 5.35
Go 5.34 5.36 4,059 417 5.35
Go #4 1.43 5.69 4,174 555 5.45
Go #2 1.51 5.70 4,317 674 5.56
Swift #3 1.45 5.71 13,689 607 12.54
mandelbrot      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* Swift #7 1.35 5.29 57,836 1147 14.15
* Swift #6 1.48 5.80 60,985 1147 14.36
Go #4 3.77 15.02 37,970 912 5.49
Go #3 3.78 15.03 38,101 900 5.82
Go 5.04 20.05 35,787 829 5.40
Swift #8 25.62 25.60—25.64 12,784 426 11.26
Swift 26.55 26.54 12,780 400 12.99
Go #8 26.70 26.77 3,199 500 5.39
Swift #5 7.27 27.13 49,312 665 13.83
Go #2 6.87 27.32 35,549 843 5.69
Go #6 6.91 27.48 35,119 707 5.69
* Swift #3   Bad Output  
fasta      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
Go 3.74 3.76 3,207 1055 5.36
Go #2 1.27 4.08 12,644 1405 5.51
Go #3 1.52 4.10 5,095 1362 5.29
* Swift 5.37 5.38 12,546 1533 13.34
* Swift #3 2.20 5.37 39,002 2097 14.73
* Swift #2 3.15 5.63—5.96 13,726 1952 14.91
Go #8 11.22 11.54—11.80 9,052 880 5.55
Swift #8 18.19 18.18—18.35 12,829 828 11.99
k-nucleotide      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
Go #7 7.58 28.83—29.08 168,186 1613 5.42
Go #3 8.20 29.98—30.69 150,413 1729 5.63
Go #6 8.30 30.22—30.75 150,442 1596 5.79
Go #4 9.27 32.00—35.21 144,650 1552 5.11
* Swift #2 14.45 54.24—57.70 273,949 1373 15.39
Go #8 61.38 62.37—62.83 558,379 752 5.20
Swift #8 166.95 168.68—173.38 650,023 658 14.46
Swift #7 223.40 226.91—248.09 650,023 607 13.04
Swift   Empty  
reverse-complement      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
Go #2 2.22 2.34—2.39 822,211 614 4.79
* Swift 2.05 2.48 825,635 1293 14.28
Go #3 2.50 2.62—2.66 821,985 609 4.88
Go #6 1.93 3.46—3.52 1,277,608 1340 4.77
Go #5   Bad Output  
Go   Empty  
binary-trees      [ Contentious. Different approaches. ]
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
Go #6 27.93 29.32—29.66 416,195 618 5.43
Swift 18.21 54.03—54.29 763,523 720 13.97
Swift #4 17.62 54.69—59.64 733,094 772 13.31
Swift #5 18.90 56.44—56.88 764,391 813 14.89
Go #2 14.21 56.45—56.55 635,613 672 5.41
Go #3 14.90 57.97—58.17 329,499 806 5.29
Go #5 14.68 57.76—58.07 386,056 957 5.41
Swift #3 18.26 58.41—58.87 733,180 868 18.46
Swift #2 18.24 58.41—58.84 732,828 822 14.89
Go 32.05 59.81—60.00 243,114 488 5.21
Go #7 32.57 61.40—61.53 241,345 531 5.30
* Swift #9   Empty  
pidigits      [ Contentious. Different libraries. ]
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* Swift #2 0.76 0.75 14,459 606 12.50
* Go #4 0.82 0.84 6,402 689 8.17
Go 1.15 1.22—1.31 7,533 715 11.71
* Go #3 1.17 1.35—1.49 6,885 610 8.50
Go #2 1.76 1.90—2.03 7,823 740 7.70
Go #6 2.47 2.48 10,703 727 5.59
Go #7 5.00 5.65 10,527 702 6.17
regex-redux      [ Contentious. Different libraries. ]
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
Go #5 3.23 5.40—5.44 297,800 817 8.13
Go #4 14.49 35.20—35.71 349,008 832 8.44
Swift #2 39.33 39.34—39.45 710,697 678 13.66
Swift 23.92 40.23—40.37 922,243 721 13.56
Swift #4 18.21 41.75—42.40 1,102,254 751 13.30
Go #3 25.15 61.72—63.46 336,585 836 5.60
Go 25.79 61.91—62.99 301,662 749 5.85
Swift

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

Go

go version go1.23.1 linux/amd64
GOAMD64=v2