The Computer Language
25.02 Benchmarks Game

Go versus Swift

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.22 32.50—32.61 13,808 1103 14.41
Go #3 8.36 33.35 3,846 975 5.31
Swift #8 34.68 34.68—34.78 13,476 470 12.23
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.46 5.45—5.53 25,002 1688 14.30
* Swift #4 5.49 5.49 25,010 1361 15.19
* Swift #5 5.52 5.50—5.55 25,010 1372 15.67
* Swift #7 5.53 5.52 25,010 1333 14.58
Swift #6 5.81 5.79—5.86 12,947 1213 13.99
Go #3 6.39 6.41 3,191 1207 5.43
Swift #8 6.66 6.66 12,808 1285 12.73
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,808 1210 13.77
Go #8 9.60 9.64 3,191 1224 5.47
Swift #9 287.49 287.49—288.02 24,867 1532 14.21
spectral-norm      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
Swift #8 5.36 5.35 24,936 411 15.00
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,705 607 13.91
mandelbrot      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* Swift #7 1.35 5.30 57,856 1147 15.57
* Swift #6 1.48 5.78 60,969 1147 15.74
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.63 25.62 12,841 426 13.44
Swift 26.55 26.54 12,853 400 13.78
Go #8 26.70 26.77 3,199 500 5.39
Swift #5 7.28 27.12 49,291 665 14.09
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
* Swift #2 2.24 4.74—5.94 13,767 1952 15.21
Go #2 1.27 4.08 12,644 1405 5.51
Go #3 1.52 4.10 5,095 1362 5.29
* Swift #3 2.20 5.37 39,313 2097 16.81
* Swift 5.43 5.42—5.47 12,640 1533 14.40
Go #8 11.22 11.54—11.80 9,052 880 5.55
Swift #8 18.86 18.86—18.92 12,837 828 13.46
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.46 55.16—55.44 273,932 1373 14.99
Go #8 61.38 62.37—62.83 558,379 752 5.20
Swift #8 167.99 175.66—188.61 904,810 658 14.96
Swift #7 225.53 231.92—242.63 649,970 607 14.99
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 1.97 2.41 825,594 1293 16.00
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.32 54.27—54.38 763,609 720 15.54
Swift #4 17.69 55.61—57.68 733,131 772 15.64
Go #2 14.21 56.45—56.55 635,613 672 5.41
Swift #5 18.99 56.13—58.05 764,781 813 14.50
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 #2 18.36 58.30—64.86 733,131 822 15.77
Swift #3 18.24 58.63—59.13 733,000 868 14.57
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,238 606 13.58
* 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 38.81 38.84—39.05 710,750 678 14.74
Swift 23.39 39.78—39.91 922,284 721 13.23
Swift #4 18.22 41.22—41.58 1,099,583 751 14.65
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
Go

go version go1.23.1 linux/amd64
GOAMD64=v2

Swift

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