The Computer Language
24.11 Benchmarks Game

Swift versus Java 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
* Swift #3 8.32 19,440 1103 32.99
Swift #8 35.13 19,444 470 35.12
Java #3 39.96 44,308 1264 40.06
Java 10.85 44,612 1289 42.80
Java #2 45.77 42,552 520 45.83
Java #8 45.90 42,568 517 45.97
n-body
source secs mem gz cpu secs
* 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
Swift #8 6.65 19,440 1285 6.65
Java #4 6.88 42,028 1495 6.91
Java #5 7.30 43,424 1435 7.36
Java #2 7.48 42,260 1430 7.52
Java #3 7.49 42,292 1436 7.52
Java #8 7.59 42,924 1322 7.64
Swift 7.85 19,440 1210 7.85
Java 7.84 42,652 1437 7.88
Swift #9 288.23 19,440 1532 288.20
spectral-norm
source secs mem gz cpu secs
Swift #8 5.33 19,568 411 5.33
Java #8 5.43 43,368 453 5.49
Swift #3 1.43 19,440 607 5.69
Java #3 1.57 44,160 762 5.93
Java #2 1.61 43,028 956 6.08
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
Java #2 4.08 82,216 802 16.06
Java #4 4.41 105,000 667 16.14
Java #6 4.19 82,232 808 16.42
Java 24.50 42,272 671 24.57
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
Java #3 6.96 82,972 910 27.54
Java #8 27.67 45,844 441 27.79
* Swift #3   Bad Output  
fasta
source secs mem gz cpu secs
Java #4 3.28 44,352 1528 3.40
Java #6 1.16 49,848 2549 3.71
* Swift #2 2.11 19,440 1952 3.76
Java #5 1.24 49,640 2478 4.13
Java #2 4.45 48,896 1259 4.60
* Swift 5.15 19,440 1533 5.14
* Swift #3 2.18 31,248 2097 5.40
Java #8 10.12 182,140 894 10.66
Swift #8 18.86 19,972 828 18.86
k-nucleotide
source secs mem gz cpu secs
Java 4.92 427,448 1821 15.77
Java #6 7.27 426,032 1614 25.17
Java #3 7.34 426,540 1642 25.47
Java #4 34.33 197,748 1887 34.67
Java #5 22.10 222,396 2225 48.14
* Swift #2 14.54 260,820 1373 55.20
Java #8 78.46 2,083,000 786 80.86
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
* Swift 1.95 798,228 1293 2.39
Java #6 3.15 2,032,996 760 3.79
Java #5 4.72 1,097,732 1115 4.84
Java #4 5.65 1,891,656 656 5.77
Java #7 23.98 1,037,708 1654 6.26
Java #3   Bad Output  
binary-trees
source secs mem gz cpu secs
Java #4 4.41 1,821,244 846 5.14
Java #6 4.87 1,782,568 535 5.63
Java #3 4.85 1,769,500 546 5.65
Java #2 5.09 1,820,068 558 5.83
Java #8 6.57 1,767,108 596 7.29
Java #7 2.62 1,803,192 841 8.14
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
* Swift #2 0.75 19,440 606 0.75
* Java #3 0.80 41,900 770 0.83
* Java #2 1.29 45,768 944 1.37
Java 7.68 482,056 807 8.75
regex-redux
source secs mem gz cpu secs
Java #2 1.55 372,764 2201 3.16
Java 8.47 575,552 875 16.69
Java #6 5.60 1,237,440 746 17.12
Java #3 5.25 611,476 935 17.25
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
Swift

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

Java

java 23 2024-09-17
Java HotSpot(TM) 64-Bit Server VM
(build 23+37-2369,
mixed mode, sharing)