The Computer Language
Benchmarks Game

Swift versus Java fastest programs

Always look at the source code.

These are only the fastest programs. Do some of them use manually vectorized SIMD? Look at the other programs. They may seem more-like a fair comparison to you.

mandelbrot
source secs mem gz busy cpu load
Swift 1.34 41,120 1140 5.34 99% 99% 100% 100%
Java 4.12 70,952 796 16.22 98% 98% 98% 99%
n-body
source secs mem gz busy cpu load
Swift 5.32 10,456 1365 5.37 100% 0% 0% 0%
Java 6.77 35,432 1489 6.82 100% 1% 0% 0%
fannkuch-redux
source secs mem gz busy cpu load
Swift 8.24 7,824 1097 32.69 98% 99% 100% 100%
Java 10.38 35,388 1282 40.84 99% 99% 98% 97%
spectral-norm
source secs mem gz busy cpu load
Swift 1.43 8,144 601 5.68 100% 99% 99% 99%
Java 1.58 39,408 756 5.97 94% 94% 96% 94%
pidigits
source secs mem gz busy cpu load
Swift 0.89 9,256 600 0.91 3% 0% 0% 99%
Java 0.93 36,088 764 0.97 4% 0% 1% 99%
fasta
source secs mem gz busy cpu load
Swift 1.41 26,396 2090 4.73 80% 80% 96% 79%
Java 1.19 44,740 2543 3.50 75% 63% 87% 70%
reverse-complement
source secs mem gz busy cpu load
Swift 1.81 781,992 1286 2.28 3% 0% 48% 75%
Java 1.53 687,864 2183 3.50 80% 46% 57% 46%
k-nucleotide
source secs mem gz busy cpu load
Swift 13.56 256,964 1367 52.30 96% 95% 96% 99%
Java 4.85 354,288 1812 15.92 80% 85% 87% 76%
regex-redux
source secs mem gz busy cpu load
Swift 23.14 1,059,096 745 48.76 92% 37% 46% 36%
Java 5.31 793,572 929 17.50 79% 78% 83% 89%
binary-trees
source secs mem gz busy cpu load
Swift 16.15 699,872 862 51.81 77% 66% 79% 100%
Java 2.48 1,725,776 835 7.86 74% 75% 97% 72%
Swift

Swift version 5.5-dev (LLVM f9e846e117057c8, Swift a58e8c181f2e258)
Target: x86_64-unknown-linux-gnu

Java

openjdk 17 2021-09-14
OpenJDK Runtime Environment (build 17+35-2724)
OpenJDK 64-Bit Server VM (build 17+35-2724, mixed mode, sharing)