The Computer Language
24.11 Benchmarks Game

C# .NET 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
source secs mem gz cpu secs
* C# .NET #5 2.27 29,584 1485 8.79
C# .NET #2 30.38 28,804 584 30.37
* Swift #3 8.32 19,440 1103 32.99
* C# .NET #9 8.40 29,608 1232 33.33
Swift #8 35.13 19,444 470 35.12
C# .NET #6 9.93 29,272 1075 39.49
C# .NET #3 11.01 29,020 1117 43.46
C# .NET #8 43.80 28,760 519 43.78
n-body
source secs mem gz cpu secs
* C# .NET #9 3.17 28,604 2480 3.17
* C# .NET #4 3.75 28,504 2137 3.75
* C# .NET #7 4.80 28,564 1715 4.80
* C# .NET #6 4.83 28,512 1754 4.83
* Swift #3 5.43 19,440 1688 5.43
* Swift #4 5.46 19,440 1361 5.46
* Swift #5 5.49 19,440 1372 5.49
* Swift #7 5.50 19,440 1333 5.50
Swift #6 5.78 19,440 1213 5.78
C# .NET #3 6.65 29,280 1311 6.64
Swift #8 6.65 19,440 1285 6.65
C# .NET #2 6.89 29,284 1339 6.89
C# .NET #8 7.21 29,068 1335 7.21
C# .NET 7.66 29,380 1424 7.66
C# .NET #0 7.66 29,360 1342 7.66
Swift 7.85 19,440 1210 7.85
Swift #9 288.23 19,440 1532 288.20
spectral-norm
source secs mem gz cpu secs
* C# .NET #5 0.94 33,752 776 3.42
Swift #8 5.33 19,568 411 5.33
C# .NET #8 5.41 29,720 441 5.40
Swift #3 1.43 19,440 607 5.69
C# .NET #2 1.52 29,864 1084 5.78
C# .NET #3 1.54 31,460 890 5.80
mandelbrot
source secs mem gz cpu secs
* Swift #7 1.38 49,024 1147 5.49
* Swift #6 1.46 51,840 1147 5.78
* C# .NET #7 3.21 66,484 915 12.50
* C# .NET 3.93 64,440 1980 15.41
* C# .NET #9 3.93 64,332 822 15.45
C# .NET #5 4.06 63,344 851 15.87
Swift #8 25.59 19,492 426 25.59
C# .NET #8 26.41 29,820 492 26.41
Swift 26.45 19,440 400 26.45
C# .NET #3 6.79 61,964 722 26.79
Swift #5 7.25 43,648 665 27.03
C# .NET #2 46.19 29,604 504 46.19
* Swift #3   Bad Output  
fasta
source secs mem gz cpu secs
C# .NET #9 1.21 29,432 1512 1.21
* Swift #2 2.11 19,440 1952 3.76
* Swift 5.15 19,440 1533 5.14
* Swift #3 2.18 31,248 2097 5.40
C# .NET #5 1.48 50,620 1702 5.45
C# .NET 1.70 36,636 2113 6.23
C# .NET #8 11.15 30,052 883 11.17
Swift #8 106.65 19,440 833 106.65
k-nucleotide
source secs mem gz cpu secs
C# .NET 3.18 181,724 2046 10.77
C# .NET #6 5.63 180,500 1615 14.88
C# .NET #4 12.06 612,408 1725 42.10
C# .NET #7 42.74 613,184 1449 43.35
* Swift #2 14.54 260,820 1373 55.20
C# .NET #8 75.50 1,371,044 736 76.56
Swift #8 181.50 627,328 658 180.87
Swift #7 233.16 627,092 607 232.52
Swift   Make Error  
reverse-complement
source secs mem gz cpu secs
C# .NET #9 0.59 733,932 2641 1.37
* Swift 1.95 798,228 1293 2.39
C# .NET 3.14 583,252 1130 3.18
C# .NET #6 1.55 1,027,196 1627 3.76
C# .NET #5 2.53 1,025,008 1620 3.83
C# .NET #7 1.54 927,984 1312 4.25
C# .NET #3 8.47 1,380,908 934 13.21
binary-trees
source secs mem gz cpu secs
C# .NET #8 13.50 883,524 601 15.31
C# .NET #7 5.34 1,074,228 706 17.42
C# .NET #2 5.37 1,083,480 717 17.60
C# .NET 6.11 3,178,448 668 19.93
C# .NET #3 6.45 2,900,008 688 20.33
Swift 18.28 737,152 720 54.20
Swift #8 54.90 402,048 567 54.89
Swift #4 17.49 707,456 772 55.84
Swift #5 18.89 738,048 813 56.25
Swift #2 18.29 707,456 822 58.16
Swift #3 18.18 707,584 868 58.24
* Swift #9   Make Error  
C# .NET #6   Make Error  
pidigits
source secs mem gz cpu secs
* Swift #2 0.75 19,440 606 0.75
* C# .NET #6 0.82 30,744 1182 0.82
* C# .NET #5 0.84 33,264 990 0.88
* C# .NET #4 1.29 31,392 1135 1.29
C# .NET #7 7.15 38,160 579 7.25
regex-redux
source secs mem gz cpu secs
C# .NET #2 1.36 402,516 1881 2.60
C# .NET 4.60 599,212 641 4.83
C# .NET #5 1.74 614,536 679 5.02
C# .NET #4 8.65 854,996 854 29.97
Swift #2 38.80 686,136 678 38.80
Swift 23.40 891,792 721 39.65
Swift #4 18.30 1,064,768 751 41.36
C# .NET

.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