The Computer Language
24.11 Benchmarks Game

Swift versus C++ g++ 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++ g++ #6 3.31 19,760 1535 13.11
* C++ g++ #7 14.03 19,760 1156 14.03
C++ g++ #5 7.85 19,760 987 30.68
* Swift #3 8.32 19,440 1103 32.99
C++ g++ #4 8.92 19,760 1445 35.00
Swift #8 35.13 19,444 470 35.12
C++ g++ #2 9.13 19,760 1446 35.73
C++ g++ #3 37.88 19,760 600 37.87
C++ g++ 10.49 19,760 1065 41.21
n-body
source secs mem gz cpu secs
* C++ g++ #0 2.15 19,760 1933 2.15
* C++ g++ #7 4.11 19,760 1815 4.11
C++ g++ #9 5.14 19,760 1536 5.14
C++ g++ #3 5.32 19,760 1402 5.32
* Swift #3 5.43 19,440 1688 5.43
* C++ g++ #4 5.45 19,760 1434 5.45
* 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++ g++ #2 6.02 19,352 1524 6.01
C++ g++ #5 6.32 19,760 1544 6.32
C++ g++ 6.61 19,760 1666 6.61
Swift #8 6.65 19,440 1285 6.65
C++ g++ #6 6.93 19,760 1674 6.93
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++ g++ #6 0.73 19,760 1050 2.86
* C++ g++ #5 1.33 19,760 1050 5.28
Swift #8 5.33 19,568 411 5.33
C++ g++ 5.33 19,760 459 5.33
Swift #3 1.43 19,440 607 5.69
C++ g++ #7 1.52 19,512 1284 6.04
mandelbrot
source secs mem gz cpu secs
* C++ g++ #4 0.89 35,344 3554 3.45
* C++ g++ 0.89 34,952 1797 3.47
* C++ g++ #6 0.98 35,080 1014 3.87
* Swift #7 1.38 49,024 1147 5.49
* Swift #6 1.46 51,840 1147 5.78
C++ g++ #0 2.35 35,476 2752 9.30
* C++ g++ #7 4.86 35,176 749 13.28
C++ g++ #5 13.44 34,636 596 13.43
C++ g++ #9 3.52 35,120 732 13.55
C++ g++ #2 16.95 34,636 700 16.94
Swift #8 25.59 19,492 426 25.59
Swift 26.45 19,440 400 26.45
Swift #5 7.25 43,648 665 27.03
C++ g++ #3 27.37 19,760 421 27.36
* Swift #3   Bad Output  
fasta
source secs mem gz cpu secs
C++ g++ #9 0.78 19,352 2758 1.54
C++ g++ #2 1.84 19,760 1129 1.84
C++ g++ 1.92 19,760 1064 1.92
C++ g++ #3 2.63 19,760 1311 2.63
C++ g++ #7 0.87 19,760 2711 3.05
C++ g++ #4 3.32 19,760 1291 3.32
C++ g++ #5 1.06 19,760 2345 3.66
* Swift #2 2.11 19,440 1952 3.76
C++ g++ #6 1.07 19,760 2326 4.01
* Swift 5.15 19,440 1533 5.14
* Swift #3 2.18 31,248 2097 5.40
Swift #8 106.65 19,440 833 106.65
k-nucleotide
source secs mem gz cpu secs
C++ g++ #2 2.01 156,592 1634 5.98
C++ g++ #3 4.19 165,580 1280 13.94
C++ g++ 6.96 757,156 1452 14.75
* Swift #2 14.54 260,820 1373 55.20
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++ g++ #2 0.74 499,916 2099 0.74
* Swift 1.95 798,228 1293 2.39
C++ g++ #6 3.30 1,517,824 1827 4.38
C++ g++ 6.52 980,156 599 6.51
C++ g++ #5 37.59 771,632 704 37.58
C++ g++ #3   Bad Output  
binary-trees
source secs mem gz cpu secs
C++ g++ #7 0.97 201,512 896 3.40
C++ g++ #5 1.16 200,724 891 4.10
C++ g++ #9 1.74 136,120 815 4.63
C++ g++ #3 1.91 265,636 951 4.74
C++ g++ #6 1.91 266,120 851 4.77
C++ g++ #4 2.22 266,136 826 5.20
C++ g++ 2.65 2,153,044 760 9.23
C++ g++ #2 22.83 265,840 514 22.82
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  
pidigits
source secs mem gz cpu secs
C++ g++ #4 0.71 19,760 521 0.71
* C++ g++ #5 0.73 19,760 804 0.73
* Swift #2 0.75 19,440 606 0.75
regex-redux
source secs mem gz cpu secs
C++ g++ #6 1.15 276,336 2856 2.24
C++ g++ #3 12.38 215,640 859 17.95
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++ g++   Make Error  
C++ g++ #2   Make Error  
C++ g++ #5   Make Error  
C++ g++ #4   Make Error  
Swift

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

C++ g++

g++ (Ubuntu 14.2.0-4ubuntu2) 14.2.0