The Computer Language
25.02 Benchmarks Game

C# 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
* C# #5 2.35 9.03 33,559 1485 7.63
C# #2 30.41 30.39 32,924 584 8.13
* Swift #3 8.22 32.50—32.61 13,808 1103 14.41
* C# #9 8.43 33.37 34,038 1232 7.74
Swift #8 34.68 34.68—34.78 13,476 470 12.23
C# #6 9.95 39.50—39.54 33,300 1075 7.64
C# #3 11.04 44.49—46.04 33,182 1117 7.89
C# #8 43.84 43.83—43.87 32,858 519 7.51
n-body      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* C# #9 3.20 3.18 32,059 2480 7.92
* C# #4 3.77 3.75 32,215 2137 8.55
* C# #7 4.83 4.81 32,297 1715 7.54
* C# #6 4.85 4.84 32,203 1754 7.89
* 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
Swift #8 6.66 6.66 12,808 1285 12.73
C# #3 6.68 6.66 33,280 1311 7.62
C# #2 6.92 6.92 33,280 1339 7.93
C# #8 7.24 7.23 32,870 1335 7.70
C# 7.68 7.67 33,341 1424 7.60
C# #0 7.68 7.67 33,300 1342 7.60
Swift 7.89 7.88 12,808 1210 13.77
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
* C# #5 0.96 3.44—3.64 37,929 776 8.71
Swift #8 5.36 5.35 24,936 411 15.00
C# #8 5.43 5.41 33,214 441 7.70
Swift #3 1.45 5.71 13,705 607 13.91
C# #3 1.56 5.82 36,172 890 8.36
C# #2   Empty  
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
* C# #7 3.23 12.59—12.90 73,056 915 7.76
* C# 3.97 15.56—15.67 70,214 1980 10.98
* C# #9 3.95 15.46—15.61 70,402 822 7.95
C# #5 4.08 15.88 68,202 851 11.86
Swift #8 25.63 25.62 12,841 426 13.44
C# #8 26.42 26.42 33,915 492 7.59
Swift 26.55 26.54 12,853 400 13.78
C# #3 6.81 26.76—26.83 66,859 722 7.65
Swift #5 7.28 27.12 49,291 665 14.09
C# #2 47.72 48.00—48.46 33,300 504 7.60
* Swift #3   Bad Output  
fasta      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
C# #9 1.23 1.23 33,571 1512 7.79
* Swift #2 2.24 4.74—5.94 13,767 1952 15.21
* Swift #3 2.20 5.37 39,313 2097 16.81
* Swift 5.43 5.42—5.47 12,640 1533 14.40
C# #5 1.53 5.45—5.54 47,833 1702 7.79
C# #8 5.80 5.49 37,343 904 8.59
C# 1.80 6.22—6.38 40,841 2113 7.88
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
C# 3.26 10.80—11.05 190,829 2046 7.66
C# #6 5.73 15.07—15.28 189,972 1615 7.65
C# #4 12.25 43.35—45.07 606,466 1725 7.64
C# #7 42.96 43.57—43.83 557,740 1449 7.50
* Swift #2 14.46 55.16—55.44 273,932 1373 14.99
C# #8 87.51 79.54—80.86 1,408,664 736 7.89
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
C# #9 0.68 1.51 550,793 2641 12.35
* Swift 1.97 2.41 825,594 1293 16.00
C# 3.32 3.31—3.39 666,341 1130 7.59
C# #5 2.59 3.87 1,056,952 1620 7.47
C# #6 1.75 4.03—4.07 1,058,517 1627 7.69
C# #7 1.69 4.47—4.62 967,602 1312 11.98
C# #3 8.65 13.47—13.71 1,266,110 934 8.01
binary-trees      [ Contentious. Different approaches. ]
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
C# #2 6.47 18.08—18.35 1,107,055 717 7.59
C# #7 6.40 18.01—18.41 1,053,831 706 7.48
C# 7.20 20.10—20.51 3,005,301 668 8.11
C# #3 7.42 20.59—21.11 3,014,975 688 7.55
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
Swift #5 18.99 56.13—58.05 764,781 813 14.50
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
* Swift #9   Empty  
C# #6   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
* C# #6 0.84 0.82 34,796 1182 7.91
* C# #5 0.86 0.89 37,335 990 7.47
* C# #4 1.31 1.30 35,496 1135 7.69
C# #7 11.08 9.19—10.76 44,098 579 7.80
regex-redux      [ Contentious. Different libraries. ]
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
C# #2 1.43 2.64 402,747 1881 7.54
C# 4.63 4.83 618,988 641 7.95
C# #5 1.90 5.18—5.38 632,472 679 7.53
C# #4 8.59 30.62—33.76 882,033 854 7.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
C#

.NET SDK 9.0.100
Host Version: 9.0.0
Commit: 9d5a6a9aa4

<OutputType>Exe
<TargetFramework>net9.0
<ImplicitUsings>enable
<Nullable>enable
<AllowUnsafeBlocks>true
<ServerGarbageCollection>true
<ConcurrentGarbageCollection>true
<PublishAot>false

Swift

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