The Computer Language
22.05 Benchmarks Game

Fastest cpu secs Swift versus Java

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 cpu seconds, less gz source code.

fannkuch-redux
source mem gz cpu
Swift #3 6,644 1097 31.59
Swift 6,456 451 35.27
Java #3 35,324 1257 41.17
Java 35,824 1282 41.74
Java #2 34,244 514 44.98
n-body
source mem gz cpu
Swift #4 14,076 1355 5.28
Swift #5 10,800 1365 5.29
Swift #7 14,024 1326 5.33
Swift #8 14,028 1681 5.70
Swift #6 6,356 1194 6.11
Java #5 34,252 1429 6.79
Java #4 34,076 1489 6.79
Java #3 34,612 1430 7.50
Java #2 34,704 1424 7.50
Java 37,380 1430 7.83
Swift #3 6,452 1204 8.11
Swift #2 6,420 1192 8.68
Swift #9 14,032 1526 292.55
spectral-norm
source mem gz cpu
Swift 12,872 438 5.32
Swift #3 6,876 601 5.68
Java #3 38,428 756 5.94
Java 37,288 514 9.76
Java #2 37,368 950 10.07
mandelbrot
source mem gz cpu
Swift #7 41,804 1140 5.29
Swift #6 44,504 1141 5.43
Java #4 66,304 660 16.16
Java #2 68,860 796 16.21
Java #6 67,432 802 16.92
Swift 6,484 394 26.22
Swift #5 41,620 659 26.91
Java 34,252 665 27.75
Java #3 69,200 903 29.18
Swift #3   Bad Output  
pidigits
source mem gz cpu
Swift #2 8,132 600 0.74
Java #3 35,700 764 0.82
Java #2 38,328 938 1.53
Java 513,728 800 8.94
regex-redux
source mem gz cpu
Java 924,116 868 17.12
Java #6 728,332 740 17.16
Java #3 741,028 929 17.34
Swift #2 682,836 671 43.47
Swift 879,156 715 44.12
Swift #4 1,061,888 745 45.38
fasta
source mem gz cpu
Swift #2 7,440 1945 3.17
Java #4 36,800 1524 3.41
Java #6 42,416 2543 3.52
Java #5 42,532 2473 4.14
Java #2 36,812 1257 4.46
Swift 6,908 1526 4.52
Swift #3 26,916 2090 4.64
k-nucleotide
source mem gz cpu
Java 349,544 1812 16.17
Java #6 343,684 1607 25.67
Java #3 344,652 1635 25.73
Java #4 199,824 1882 37.48
Java #5 210,368 2219 43.27
Swift #2 257,052 1367 52.46
Swift   Make Error  
reverse-complement
source mem gz cpu
Swift 794,484 1286 2.26
Java #8 665,804 2183 3.49
Java #6 2,024,016 752 4.15
Java #5 1,088,392 1108 4.92
Java #3 1,170,232 1722 5.09
Java #4 1,881,900 651 5.41
Java #7 1,030,892 1647 23.16
binary-trees
source mem gz cpu
Java #3 2,106,820 540 5.19
Java #6 2,093,916 529 5.35
Java #4 2,079,388 840 5.44
Java #2 1,877,464 552 5.45
Java #7 2,460,388 835 7.73
Swift #5 733,388 806 41.37
Swift #3 700,092 862 43.45
Swift #2 699,876 816 44.09
Swift 733,908 714 59.11
Swift #4 700,512 765 60.93
Swift #9   Make Error  
Swift

Swift version 5.7-dev
(LLVM a177fc627109410,
Swift 31967c6df177cce)

Java

openjdk 18 2022-03-22
OpenJDK Runtime Environment
(build 18+36-2087)
OpenJDK 64-Bit Server VM
(build 18+36-2087,
mixed mode, sharing)