The Computer Language
25.03 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.20 32.45—32.61 13,722 1103 12.93
* C# #9 8.43 33.37 34,038 1232 7.74
Swift #8 34.68 34.68—34.74 13,484 470 12.33
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.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
Swift #8 6.66 6.56—6.95 12,804 1285 12.85
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,812 1210 12.10
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
* C# #5 0.96 3.44—3.64 37,929 776 8.71
Swift #8 5.36 5.35 24,859 411 14.09
C# #8 5.43 5.41 33,214 441 7.70
Swift #3 1.45 5.71 13,689 607 12.54
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.29 57,836 1147 14.15
* Swift #6 1.48 5.80 60,985 1147 14.36
* 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.62 25.60—25.64 12,784 426 11.26
C# #8 26.42 26.42 33,915 492 7.59
Swift 26.55 26.54 12,780 400 12.99
C# #3 6.81 26.76—26.83 66,859 722 7.65
Swift #5 7.27 27.13 49,312 665 13.83
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 5.37 5.38 12,546 1533 13.34
* Swift #3 2.20 5.37 39,002 2097 14.73
C# #5 1.53 5.45—5.54 47,833 1702 7.79
* Swift #2 3.15 5.63—5.96 13,726 1952 14.91
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.19 18.18—18.35 12,829 828 11.99
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.45 54.24—57.70 273,949 1373 15.39
C# #8 87.51 79.54—80.86 1,408,664 736 7.89
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
* C# #9 0.68 1.51 550,793 2641 12.35
* Swift 2.05 2.48 825,635 1293 14.28
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.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
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
* 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,459 606 12.50
* 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 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
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.3
(swift-6.0.3-RELEASE)
Target: x86_64-unknown-linux-gnu