Zig VS Java benchmarks

Current benchmark data was generated on Fri Sep 30 2022, full log can be found HERE

CONTRIBUTIONS are WELCOME!

[x86_64][2 cores] Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz (Model 85)

* -m in a file name stands for multi-threading or multi-processing

* -i in a file name stands for direct intrinsics usage. (Usage of simd intrinsics via libraries is not counted)

* -ffi in a file name stands for non-stdlib FFI usage

* (You may find time < time(user) + time(sys) for some non-parallelized programs, the overhead is from GC or JIT compiler, which are allowed to take advantage of multi-cores as that's more close to real-world scenarios.)

binarytrees

Input: 18

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2.java 766ms 12ms 414.2MB 733ms 123ms openjdk 20
java 2.java 785ms 6.1ms 409.0MB 753ms 127ms openjdk 19
java 2.java 804ms 24ms 683.4MB 853ms 203ms graal/jvm 17.0.4
java 2.java 1479ms 49ms 1081.8MB 1013ms 687ms openjdk/zgc 19
zig 1.zig 2436ms 37ms 49.1MB 2407ms 13ms zig 0.10.0-dev.4198+5e0d8a435

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2.java 179ms 6.1ms 109.2MB 173ms 30ms openjdk 19
java 2.java 185ms 15ms 110.9MB 183ms 27ms openjdk 20
zig 1.zig 197ms 0.4ms 7.2MB 183ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 2.java 210ms 21ms 165.1MB 253ms 43ms graal/jvm 17.0.4
java 2.java 345ms 11ms 240.4MB 183ms 193ms openjdk/zgc 19

edigits

Input: 250001

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 817ms 50ms 281.2MB 1387ms 120ms graal/jvm 17.0.4
java 1-m.java 822ms 47ms 207.2MB 1430ms 70ms openjdk 19
java 1-m.java 823ms 67ms 221.6MB 1443ms 67ms openjdk 20
java 1-m.java 1036ms 18ms 422.0MB 1453ms 337ms openjdk/zgc 19
zig 1.zig 4859ms 2.4ms 2.7MB 4820ms 17ms zig 0.10.0-dev.4198+5e0d8a435

Input: 100000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 420ms 13ms 189.2MB 647ms 90ms graal/jvm 17.0.4
java 1-m.java 445ms 7.5ms 116.4MB 717ms 50ms openjdk 19
java 1-m.java 451ms 8.9ms 119.1MB 730ms 53ms openjdk 20
java 1-m.java 565ms 25ms 208.9MB 750ms 180ms openjdk/zgc 19
zig 1.zig 802ms 0.7ms 2.1MB 783ms 0ms zig 0.10.0-dev.4198+5e0d8a435

fannkuch-redux

Input: 11

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2-m.zig 1224ms 8.4ms 0.8MB 2360ms 0ms zig 0.10.0-dev.4198+5e0d8a435
zig 3-i.zig 1348ms 0.9ms 0.6MB 1337ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 1-m.java 1418ms 8.8ms 91.7MB 2653ms 37ms graal/jvm 17.0.4
java 1-m.java 1579ms 40ms 42.2MB 2890ms 80ms openjdk/zgc 19
java 1-m.java 1582ms 75ms 42.1MB 3000ms 13ms openjdk 19
java 1-m.java 1585ms 94ms 44.3MB 3030ms 20ms openjdk 20
zig 2.zig 2332ms 1.5ms 0.6MB 2320ms 0ms zig 0.10.0-dev.4198+5e0d8a435
zig 1.zig 3027ms 6.5ms 0.6MB 3017ms 0ms zig 0.10.0-dev.4198+5e0d8a435

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 3-i.zig 115ms 0.9ms 0.6MB 103ms 0ms zig 0.10.0-dev.4198+5e0d8a435
zig 2-m.zig 119ms 3.5ms 0.7MB 200ms 0ms zig 0.10.0-dev.4198+5e0d8a435
zig 2.zig 200ms 0.5ms 0.6MB 190ms 0ms zig 0.10.0-dev.4198+5e0d8a435
zig 1.zig 253ms 0.5ms 0.6MB 240ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 1-m.java 263ms 5.7ms 42.2MB 420ms 10ms openjdk 19
java 1-m.java 264ms 8.7ms 44.1MB 410ms 23ms openjdk 20
java 1-m.java 292ms 38ms 100.0MB 440ms 37ms graal/jvm 17.0.4
java 1-m.java 317ms 7.1ms 44.0MB 403ms 77ms openjdk/zgc 19

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 137ms 0.7ms 0.6MB 130ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 4.java 466ms 12ms 41.7MB 540ms 17ms openjdk 19
java 4.java 470ms 6.4ms 43.9MB 547ms 13ms openjdk 20
java 4.java 526ms 14ms 43.5MB 547ms 70ms openjdk/zgc 19
java 4-m.java 549ms 6.3ms 118.4MB 850ms 47ms graal/jvm 17.0.4

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 16ms 0.1ms 0.6MB 10ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 4.java 142ms 2.0ms 41.3MB 160ms 10ms openjdk 19
java 4.java 142ms 1.7ms 42.9MB 157ms 20ms openjdk 20
java 4.java 156ms 7.9ms 82.9MB 173ms 37ms graal/jvm 17.0.4
java 4.java 201ms 3.0ms 41.3MB 170ms 63ms openjdk/zgc 19

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 2.3ms 0.7ms 0.6MB 0ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 1.java 77ms 2.0ms 58.0MB 70ms 14ms graal/jvm 17.0.4
java 1.java 83ms 3.5ms 40.6MB 80ms 10ms openjdk 20
java 1.java 89ms 4.9ms 40.5MB 78ms 10ms openjdk 19
java 1.java 136ms 2.5ms 39.9MB 80ms 68ms openjdk/zgc 19

json-serde

Input: sample 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 109ms 0.3ms 10.3MB 87ms 7ms zig 0.10.0-dev.4198+5e0d8a435

Input: canada 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 668ms 4.4ms 81.4MB 613ms 37ms zig 0.10.0-dev.4198+5e0d8a435

knucleotide

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 1155ms 7.6ms 23.6MB 1117ms 20ms zig 0.10.0-dev.4198+5e0d8a435
java 3-m.java 1499ms 3.9ms 116.2MB 2733ms 37ms openjdk 19
java 3-m.java 1513ms 13ms 114.9MB 2747ms 47ms openjdk 20
java 3-m.java 1537ms 13ms 192.2MB 2767ms 93ms graal/jvm 17.0.4
java 3-m.java 2015ms 5.0ms 174.5MB 3473ms 177ms openjdk/zgc 19

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 128ms 0.4ms 9.2MB 117ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 3-m.java 429ms 5.9ms 92.9MB 690ms 33ms openjdk 20
java 3-m.java 503ms 8.8ms 94.1MB 727ms 100ms openjdk/zgc 19
java 3-m.java 508ms 64ms 96.7MB 820ms 50ms openjdk 19
java 3-m.java 739ms 144ms 179.8MB 1260ms 90ms graal/jvm 17.0.4

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 50ms 1.2ms 2.9MB 40ms 0ms zig 0.10.0-dev.4198+5e0d8a435

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 138ms 0.4ms 2.8MB 127ms 0ms zig 0.10.0-dev.4198+5e0d8a435

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 25ms 3.4ms 1.5MB 10ms 0ms zig 0.10.0-dev.4198+5e0d8a435

mandelbrot

Input: 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 365ms 0.2ms 4.0MB 350ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 1b.java 1497ms 25ms 48.4MB 1597ms 13ms openjdk 19
java 1b.java 1521ms 27ms 50.8MB 1620ms 10ms openjdk 20
java 1b.java 1562ms 7.1ms 49.0MB 1590ms 70ms openjdk/zgc 19
java 1b.java 1590ms 16ms 122.6MB 1760ms 43ms graal/jvm 17.0.4
java 1a.java 1801ms 9.1ms 50.4MB 1880ms 23ms openjdk 20
java 1a.java 1818ms 33ms 48.6MB 1910ms 27ms openjdk 19
java 1a.java 1870ms 9.2ms 114.0MB 1970ms 33ms graal/jvm 17.0.4
java 1a.java 1875ms 16ms 49.8MB 1897ms 77ms openjdk/zgc 19
java 1.java 2059ms 4.7ms 121.0MB 2150ms 50ms graal/jvm 17.0.4
java 1.java 2148ms 6.1ms 198.9MB 2167ms 73ms openjdk 19
java 1.java 2169ms 15ms 192.9MB 2217ms 57ms openjdk 20
java 1.java 2585ms 4.9ms 567.8MB 2297ms 397ms openjdk/zgc 19
java 2.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 19
java 2.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 20
java 2.java timeout 0.0ms 0.0MB 0ms 0ms openjdk/zgc 19

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 18ms 0.8ms 0.6MB 10ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 1b.java 222ms 14ms 45.6MB 287ms 20ms openjdk 19
java 1b.java 222ms 4.0ms 44.2MB 310ms 13ms openjdk 20
java 1a.java 233ms 11ms 48.5MB 303ms 20ms openjdk 19
java 1.java 234ms 4.7ms 95.2MB 290ms 27ms openjdk 19
java 1.java 234ms 2.5ms 97.8MB 277ms 20ms openjdk 20
java 1a.java 247ms 7.5ms 101.0MB 317ms 40ms graal/jvm 17.0.4
java 1a.java 248ms 25ms 46.5MB 330ms 20ms openjdk 20
java 1.java 258ms 1.4ms 107.1MB 327ms 40ms graal/jvm 17.0.4
java 1b.java 279ms 12ms 45.9MB 300ms 67ms openjdk/zgc 19
java 1a.java 282ms 13ms 44.8MB 277ms 70ms openjdk/zgc 19
java 1b-m.java 292ms 28ms 119.1MB 423ms 37ms graal/jvm 17.0.4
java 1.java 316ms 3.9ms 111.4MB 273ms 110ms openjdk/zgc 19
java 2.java 876ms 31ms 571.2MB 1007ms 177ms openjdk 20
java 2.java 932ms 20ms 552.5MB 1033ms 197ms openjdk 19
java 2.java 1669ms 55ms 1124.2MB 1150ms 790ms openjdk/zgc 19

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 575ms 8.1ms 294.1MB 597ms 87ms openjdk 20
java 1.java 600ms 16ms 365.9MB 607ms 97ms openjdk 19
java 1.java 681ms 58ms 366.4MB 847ms 120ms graal/jvm 17.0.4
java 1.java 1088ms 1.8ms 733.5MB 740ms 500ms openjdk/zgc 19
zig 1.zig 1129ms 2.8ms 41.1MB 1100ms 13ms zig 0.10.0-dev.4198+5e0d8a435

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 229ms 0.8ms 11.3MB 213ms 3ms zig 0.10.0-dev.4198+5e0d8a435
java 1.java 245ms 3.0ms 174.2MB 243ms 63ms openjdk 19
java 1.java 246ms 3.9ms 173.9MB 263ms 43ms openjdk 20
java 1-m.java 301ms 4.0ms 244.5MB 420ms 77ms graal/jvm 17.0.4
java 1.java 465ms 8.9ms 325.2MB 287ms 230ms openjdk/zgc 19

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 260ms 4.4ms 0.7MB 247ms 0ms zig 0.10.0-dev.4198+5e0d8a435
zig 1.zig 381ms 2.3ms 0.7MB 370ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 1.java 586ms 6.5ms 87.4MB 627ms 30ms graal/jvm 17.0.4
java 1.java 638ms 5.0ms 44.2MB 647ms 20ms openjdk 19
java 1.java 643ms 3.3ms 42.4MB 650ms 23ms openjdk 20
java 1.java 705ms 4.7ms 42.0MB 663ms 73ms openjdk/zgc 19
java 2.java 2299ms 9.1ms 534.4MB 2290ms 163ms openjdk 20
java 2.java 2309ms 29ms 487.1MB 2310ms 157ms openjdk 19
java 2.java 3386ms 50ms 1654.7MB 2387ms 1197ms openjdk/zgc 19

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 28ms 0.5ms 0.7MB 20ms 0ms zig 0.10.0-dev.4198+5e0d8a435
zig 1.zig 41ms 0.3ms 0.7MB 30ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 1.java 157ms 3.9ms 42.3MB 170ms 10ms openjdk 19
java 1.java 157ms 4.7ms 42.7MB 170ms 20ms openjdk 20
java 1.java 157ms 3.0ms 87.9MB 203ms 23ms graal/jvm 17.0.4
java 1.java 214ms 4.5ms 43.5MB 183ms 63ms openjdk/zgc 19
java 2.java 480ms 11ms 354.0MB 527ms 93ms openjdk 20
java 2.java 482ms 9.4ms 345.0MB 523ms 103ms openjdk 19
java 2.java 802ms 2.3ms 484.3MB 590ms 367ms openjdk/zgc 19

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 377ms 1.1ms 6.1MB 367ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 2.java 1037ms 6.0ms 53.9MB 1073ms 20ms openjdk 20
java 2.java 1075ms 26ms 54.2MB 1107ms 23ms openjdk 19
java 2.java 1123ms 1.7ms 51.0MB 1100ms 70ms openjdk/zgc 19
java 1.java 1127ms 18ms 86.7MB 1147ms 33ms openjdk 20
java 1.java 1140ms 16ms 84.6MB 1163ms 30ms openjdk 19
java 1.java 1405ms 18ms 110.5MB 1353ms 103ms openjdk/zgc 19
java 1.java 1613ms 33ms 164.5MB 2260ms 73ms graal/jvm 17.0.4
java 2-m.java 2068ms 15ms 130.4MB 3833ms 50ms graal/jvm 17.0.4

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 79ms 0.6ms 2.5MB 70ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 1.java 248ms 2.6ms 60.4MB 283ms 17ms openjdk 20
java 1.java 250ms 2.8ms 62.3MB 283ms 17ms openjdk 19
java 1.java 313ms 4.1ms 59.2MB 283ms 73ms openjdk/zgc 19
java 2.java 329ms 2.4ms 48.7MB 363ms 20ms openjdk 19
java 2.java 330ms 3.1ms 46.8MB 360ms 20ms openjdk 20
java 1-m.java 351ms 14ms 135.8MB 467ms 67ms graal/jvm 17.0.4
java 2.java 388ms 3.1ms 46.1MB 357ms 77ms openjdk/zgc 19
java 2-m.java 669ms 8.9ms 127.2MB 1167ms 67ms graal/jvm 17.0.4

pidigits

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 1927ms 1.2ms 2.4MB 1903ms 7ms zig 0.10.0-dev.4198+5e0d8a435
java 1.java timeout 0.0ms 0.0MB 0ms 0ms graal/jvm 17.0.4
java 1.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 19
java 1.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 20
java 1.java timeout 0.0ms 0.0MB 0ms 0ms openjdk/zgc 19

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 440ms 0.7ms 2.0MB 423ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 1.java 1515ms 17ms 317.7MB 1813ms 113ms openjdk 19
java 1.java 1529ms 15ms 309.2MB 1803ms 107ms openjdk 20
java 1.java 1564ms 6.5ms 384.4MB 1910ms 120ms graal/jvm 17.0.4
java 1.java 2102ms 48ms 967.5MB 1730ms 713ms openjdk/zgc 19

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2-m.zig 910ms 2.3ms 1.7MB 1743ms 0ms zig 0.10.0-dev.4198+5e0d8a435
zig 2.zig 1724ms 0.6ms 1.7MB 1710ms 0ms zig 0.10.0-dev.4198+5e0d8a435
zig 1.zig 3843ms 0.5ms 0.7MB 3830ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 2-m.java 4360ms 25ms 107.0MB 8363ms 43ms graal/jvm 17.0.4
java 2.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 19
java 2.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 20
java 2.java timeout 0.0ms 0.0MB 0ms 0ms openjdk/zgc 19

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2-m.zig 248ms 13ms 0.8MB 430ms 3ms zig 0.10.0-dev.4198+5e0d8a435
zig 2.zig 434ms 0.2ms 0.7MB 427ms 0ms zig 0.10.0-dev.4198+5e0d8a435
zig 1.zig 951ms 0.8ms 0.7MB 940ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 2-m.java 1256ms 53ms 103.4MB 2277ms 47ms graal/jvm 17.0.4
java 2-m.java 1633ms 55ms 42.8MB 3080ms 23ms openjdk 20
java 2-m.java 1736ms 112ms 45.0MB 3293ms 10ms openjdk 19
java 2-m.java 1749ms 139ms 42.7MB 3200ms 77ms openjdk/zgc 19

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2-m.zig 68ms 2.4ms 0.8MB 103ms 0ms zig 0.10.0-dev.4198+5e0d8a435
zig 2.zig 112ms 1.3ms 0.7MB 100ms 0ms zig 0.10.0-dev.4198+5e0d8a435
zig 1.zig 244ms 0.4ms 0.7MB 233ms 0ms zig 0.10.0-dev.4198+5e0d8a435
java 2-m.java 436ms 26ms 100.2MB 727ms 37ms graal/jvm 17.0.4
java 2-m.java 577ms 28ms 44.3MB 1013ms 20ms openjdk 20
java 2-m.java 583ms 8.5ms 43.6MB 1033ms 7ms openjdk 19
java 2-m.java 632ms 24ms 44.2MB 1010ms 77ms openjdk/zgc 19