Nim VS Java benchmarks

Current benchmark data was generated on Thu Dec 26 2024, full log can be found HERE

CONTRIBUTIONS are WELCOME!

[x86_64][4 cores] AMD EPYC 7763 64-Core Processor (Model 1)

* -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 472ms 8.6ms 637.8MB 543ms 123ms openjdk 23
java 2-m.java 514ms 38ms 645.2MB 707ms 140ms graal/jvm 17.0.8
java 2.java 517ms 31ms 573.2MB 550ms 133ms openjdk 21
nim 2.nim 785ms 3.0ms 34.9MB 760ms 10ms nim 2.2.0
nim 2.nim 961ms 14ms 35.2MB 940ms 7ms nim/clang 2.2.0
java 2.java 1171ms 9.3ms 1048.8MB 573ms 760ms openjdk/zgc 21

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 74ms 2.0ms 5.5MB 60ms 0ms nim 2.2.0
nim 2.nim 91ms 0.8ms 5.8MB 80ms 0ms nim/clang 2.2.0
java 2-m.java 123ms 1.9ms 167.2MB 150ms 37ms openjdk 21
java 2.java 126ms 5.3ms 98.3MB 163ms 20ms openjdk 23
java 2-m.java 150ms 5.9ms 230.3MB 213ms 60ms graal/jvm 17.0.8
java 2.java 309ms 2.7ms 243.4MB 163ms 197ms openjdk/zgc 21

coro-prime-sieve

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 1820ms 108ms 265.6MB 6813ms 120ms openjdk 21
java 1-m.java 2317ms 164ms 239.6MB 8720ms 137ms openjdk 23
java 1-m.java 2754ms 346ms 1205.4MB 8730ms 1103ms openjdk/zgc 21
nim 1.nim timeout 0.0ms 544.3MB 2423ms 2120ms nim 2.2.0
nim 1.nim timeout 0.0ms 554.6MB 2460ms 2077ms nim/clang 2.2.0

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 421ms 56ms 93.9MB 1347ms 67ms openjdk 23
java 1-m.java 422ms 20ms 115.8MB 1380ms 77ms openjdk 21
java 1-m.java 665ms 19ms 212.5MB 1790ms 253ms openjdk/zgc 21
nim 1.nim 4402ms 15ms 519.7MB 2163ms 1810ms nim/clang 2.2.0
nim 1.nim 4533ms 11ms 519.3MB 2207ms 1900ms nim 2.2.0

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 184ms 1.7ms 1.5MB 167ms 3ms nim 2.2.0
nim 2.nim 238ms 2.5ms 1.8MB 230ms 0ms nim/clang 2.2.0
java 4.java 443ms 1.8ms 106.0MB 607ms 50ms graal/jvm 17.0.8
java 4.java 451ms 6.8ms 47.5MB 537ms 17ms openjdk 21
java 4.java 460ms 1.9ms 49.1MB 553ms 10ms openjdk 23
nim 1.nim 569ms 1.2ms 1.8MB 447ms 107ms nim/clang 2.2.0
java 4.java 573ms 7.3ms 46.9MB 547ms 140ms openjdk/zgc 21
nim 1.nim 601ms 6.4ms 1.5MB 473ms 110ms nim 2.2.0

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 21ms 0.3ms 1.5MB 10ms 0ms nim 2.2.0
nim 2.nim 26ms 0.2ms 1.8MB 20ms 0ms nim/clang 2.2.0
nim 1.nim 60ms 0.6ms 1.8MB 40ms 7ms nim/clang 2.2.0
nim 1.nim 62ms 0.9ms 1.5MB 47ms 3ms nim 2.2.0
java 4.java 121ms 5.7ms 46.6MB 153ms 27ms openjdk 21
java 4-m.java 128ms 0.7ms 96.1MB 177ms 33ms graal/jvm 17.0.8
java 4.java 128ms 3.8ms 48.0MB 173ms 17ms openjdk 23
java 4.java 241ms 0.7ms 45.8MB 163ms 133ms openjdk/zgc 21

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 1.1ms 0.0ms 1.5MB 0ms 0ms nim 2.2.0
nim 1.nim 1.2ms 0.0ms 1.9MB 0ms 0ms nim/clang 2.2.0
java 1.java 66ms 2.0ms 58.9MB 66ms 22ms graal/jvm 17.0.8
java 1.java 71ms 3.8ms 44.7MB 72ms 14ms openjdk 23
java 1.java 75ms 1.7ms 43.9MB 74ms 22ms openjdk 21
java 1.java 189ms 4.6ms 44.4MB 82ms 134ms openjdk/zgc 21

http-server

Input: 3000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 1022ms 36ms 98.7MB 287ms 703ms nim 2.2.0
nim 1.nim 1047ms 8.3ms 98.9MB 273ms 747ms nim/clang 2.2.0

Input: 500

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 163ms 1.6ms 18.1MB 40ms 110ms nim 2.2.0
nim 1.nim 165ms 3.8ms 18.3MB 40ms 107ms nim/clang 2.2.0

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 110ms 0.6ms 1.6MB 100ms 0ms nim/clang 2.2.0
nim 2.nim 114ms 1.9ms 1.4MB 103ms 0ms nim 2.2.0
nim 1.nim timeout 0.0ms 1.3MB 4990ms 0ms nim 2.2.0
nim 1.nim timeout 0.0ms 1.5MB 4990ms 0ms nim/clang 2.2.0

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 323ms 0.9ms 1.6MB 313ms 0ms nim/clang 2.2.0
nim 2.nim 339ms 2.7ms 1.4MB 330ms 0ms nim 2.2.0
nim 1.nim timeout 0.0ms 1.3MB 4987ms 0ms nim 2.2.0
nim 1.nim timeout 0.0ms 1.5MB 4990ms 0ms nim/clang 2.2.0

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 48ms 1.1ms 1.5MB 40ms 0ms nim/clang 2.2.0
nim 2.nim 51ms 0.4ms 1.3MB 40ms 0ms nim 2.2.0
nim 1.nim 481ms 2.8ms 1.5MB 470ms 0ms nim/clang 2.2.0
nim 1.nim 487ms 4.3ms 1.3MB 477ms 0ms nim 2.2.0

mandelbrot

Input: 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 388ms 1.8ms 4.8MB 377ms 0ms nim/clang 2.2.0
nim 1.nim 579ms 3.7ms 4.5MB 563ms 0ms nim 2.2.0
java 1b.java 1144ms 5.6ms 55.2MB 1240ms 20ms openjdk 23
java 1b.java 1154ms 20ms 54.5MB 1263ms 13ms openjdk 21
java 1b.java 1215ms 43ms 115.3MB 1453ms 43ms graal/jvm 17.0.8
java 1.java 1258ms 9.1ms 140.0MB 1367ms 53ms graal/jvm 17.0.8
java 1b.java 1278ms 22ms 53.1MB 1280ms 133ms openjdk/zgc 21
java 1a.java 1653ms 3.6ms 56.4MB 1750ms 20ms openjdk 23
java 1a.java 1658ms 10ms 54.7MB 1753ms 23ms openjdk 21
java 1a.java 1687ms 17ms 105.9MB 1800ms 40ms graal/jvm 17.0.8
java 1.java 1695ms 3.1ms 202.5MB 1760ms 40ms openjdk 21
java 1.java 1700ms 7.7ms 305.2MB 1760ms 47ms openjdk 23
java 1a.java 1774ms 20ms 51.1MB 1747ms 137ms openjdk/zgc 21
java 1.java 2369ms 30ms 864.4MB 1823ms 643ms openjdk/zgc 21
java 2.java timeout 0.0ms 712.6MB 5277ms 120ms openjdk 21
java 2.java timeout 0.0ms 764.7MB 5277ms 123ms openjdk 23
java 2.java timeout 0.0ms 3438.6MB 3370ms 1980ms openjdk/zgc 21

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 18ms 0.3ms 1.9MB 10ms 0ms nim/clang 2.2.0
nim 1.nim 26ms 0.8ms 1.6MB 17ms 0ms nim 2.2.0
java 1b-m.java 177ms 0.2ms 51.0MB 263ms 30ms openjdk 23
java 1-m.java 189ms 3.0ms 86.9MB 263ms 23ms openjdk 23
java 1a-m.java 191ms 1.6ms 50.7MB 287ms 23ms openjdk 21
java 1b-m.java 192ms 2.2ms 49.3MB 297ms 23ms openjdk 21
java 1-m.java 193ms 4.0ms 82.0MB 273ms 20ms openjdk 21
java 1a-m.java 197ms 6.1ms 52.1MB 297ms 23ms openjdk 23
java 1-m.java 202ms 12ms 118.4MB 303ms 43ms graal/jvm 17.0.8
java 1a-m.java 218ms 9.5ms 102.2MB 320ms 47ms graal/jvm 17.0.8
java 1b-m.java 229ms 25ms 104.7MB 390ms 40ms graal/jvm 17.0.8
java 1b.java 310ms 4.9ms 47.5MB 300ms 140ms openjdk/zgc 21
java 1a.java 310ms 2.5ms 49.9MB 287ms 140ms openjdk/zgc 21
java 1.java 337ms 1.1ms 114.3MB 267ms 167ms openjdk/zgc 21
java 2-m.java 564ms 7.2ms 761.7MB 860ms 90ms openjdk 23
java 2-m.java 591ms 5.7ms 611.0MB 820ms 130ms openjdk 21
java 2.java 1587ms 17ms 1357.2MB 847ms 1043ms openjdk/zgc 21

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 399ms 2.9ms 679.9MB 477ms 80ms openjdk 21
java 1.java 403ms 3.0ms 541.9MB 500ms 83ms openjdk 23
java 1-m.java 425ms 28ms 633.5MB 633ms 103ms graal/jvm 17.0.8
nim 1.nim 571ms 1.4ms 34.9MB 550ms 10ms nim 2.2.0
nim 1.nim 619ms 5.8ms 35.2MB 603ms 3ms nim/clang 2.2.0
java 1.java 1076ms 5.7ms 970.2MB 450ms 737ms openjdk/zgc 21

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 120ms 0.7ms 9.6MB 107ms 0ms nim 2.2.0
nim 1.nim 134ms 1.6ms 9.9MB 127ms 0ms nim/clang 2.2.0
java 1-m.java 164ms 4.5ms 206.6MB 227ms 50ms openjdk 21
java 1-m.java 165ms 2.1ms 158.7MB 233ms 50ms openjdk 23
java 1-m.java 233ms 22ms 255.7MB 400ms 50ms graal/jvm 17.0.8
java 1.java 410ms 6.6ms 341.7MB 223ms 260ms openjdk/zgc 21

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 322ms 1.4ms 1.8MB 310ms 0ms nim 2.2.0
nim 2.nim 340ms 1.0ms 2.0MB 330ms 0ms nim/clang 2.2.0
java 1.java 441ms 4.4ms 45.6MB 480ms 17ms openjdk 21
java 1.java 445ms 0.3ms 47.8MB 470ms 23ms openjdk 23
java 1.java 446ms 4.2ms 87.2MB 473ms 27ms graal/jvm 17.0.8
java 1.java 567ms 1.9ms 44.8MB 483ms 137ms openjdk/zgc 21
java 2.java 1234ms 16ms 564.0MB 1367ms 73ms openjdk 21
java 2.java 1244ms 9.3ms 758.8MB 1343ms 120ms openjdk 23
java 2.java 3320ms 110ms 2546.4MB 1653ms 1867ms openjdk/zgc 21

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 34ms 0.4ms 1.8MB 23ms 0ms nim 2.2.0
nim 2.nim 36ms 0.9ms 2.0MB 30ms 0ms nim/clang 2.2.0
java 1.java 117ms 3.9ms 45.5MB 150ms 17ms openjdk 21
java 1.java 122ms 1.4ms 48.3MB 157ms 17ms openjdk 23
java 1-m.java 131ms 2.3ms 85.4MB 163ms 33ms graal/jvm 17.0.8
java 1.java 244ms 1.6ms 46.4MB 157ms 140ms openjdk/zgc 21
java 2-m.java 301ms 3.3ms 346.2MB 433ms 60ms openjdk 21
java 2-m.java 315ms 9.1ms 412.2MB 433ms 80ms openjdk 23
java 2.java 700ms 2.1ms 533.6MB 483ms 410ms openjdk/zgc 21

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 273ms 4.2ms 41.5MB 260ms 3ms nim 2.2.0
nim 1.nim 323ms 13ms 41.8MB 307ms 0ms nim/clang 2.2.0
java 1.java 395ms 9.8ms 118.5MB 437ms 27ms openjdk 23
java 1.java 402ms 6.8ms 114.9MB 450ms 27ms openjdk 21
java 1.java 580ms 2.9ms 112.7MB 480ms 167ms openjdk/zgc 21
java 1-m.java 607ms 14ms 215.8MB 877ms 70ms graal/jvm 17.0.8
java 2.java 780ms 5.5ms 57.3MB 840ms 17ms openjdk 21
java 2.java 783ms 4.7ms 60.6MB 827ms 27ms openjdk 23
java 2.java 840ms 2.2ms 53.4MB 767ms 150ms openjdk/zgc 21
java 2-m.java 1341ms 35ms 274.3MB 2353ms 137ms graal/jvm 17.0.8

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 54ms 3.5ms 11.5MB 43ms 0ms nim 2.2.0
nim 1.nim 64ms 1.8ms 11.8MB 57ms 0ms nim/clang 2.2.0
java 1.java 152ms 7.5ms 64.8MB 200ms 17ms openjdk 21
java 1.java 154ms 1.6ms 68.0MB 193ms 23ms openjdk 23
java 1-m.java 227ms 37ms 144.0MB 320ms 50ms graal/jvm 17.0.8
java 2.java 261ms 5.7ms 49.6MB 330ms 13ms openjdk 21
java 2.java 261ms 2.9ms 50.7MB 317ms 13ms openjdk 23
java 1.java 284ms 4.4ms 61.3MB 207ms 147ms openjdk/zgc 21
java 2.java 371ms 6.5ms 47.3MB 307ms 143ms openjdk/zgc 21
java 2-m.java 536ms 96ms 154.5MB 957ms 63ms graal/jvm 17.0.8

regex-redux

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 1632ms 11ms 152.4MB 1597ms 17ms nim/clang 2.2.0
nim 1.nim 1664ms 13ms 151.5MB 1623ms 20ms nim 2.2.0
java 3.java timeout 0.0ms 409.0MB 5410ms 90ms graal/jvm 17.0.8
java 3.java timeout 0.0ms 304.2MB 5307ms 73ms openjdk 21
java 3.java timeout 0.0ms 306.8MB 5310ms 73ms openjdk 23
java 3.java timeout 0.0ms 466.9MB 4937ms 330ms openjdk/zgc 21

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 172ms 1.1ms 16.8MB 160ms 0ms nim/clang 2.2.0
nim 1.nim 176ms 2.7ms 16.5MB 160ms 0ms nim 2.2.0
java 3-m.java 773ms 24ms 180.9MB 1133ms 67ms graal/jvm 17.0.8
java 3-m.java 809ms 29ms 131.9MB 1213ms 43ms openjdk 21
java 3-m.java 825ms 12ms 134.5MB 1220ms 37ms openjdk 23
java 3.java 977ms 40ms 133.9MB 1163ms 190ms openjdk/zgc 21

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2-m.java 1948ms 13ms 47.8MB 7413ms 27ms openjdk 21
java 2-m.java 1964ms 8.0ms 48.6MB 7447ms 27ms openjdk 23
java 2-m.java 2087ms 5.7ms 47.2MB 7467ms 150ms openjdk/zgc 21
java 2-m.java 2479ms 18ms 100.1MB 8663ms 50ms graal/jvm 17.0.8
nim 1.nim 3574ms 1.5ms 1.6MB 3560ms 0ms nim/clang 2.2.0
nim 1.nim 3592ms 5.1ms 1.4MB 3583ms 0ms nim 2.2.0

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2-m.java 585ms 4.5ms 47.8MB 2020ms 37ms openjdk 21
java 2-m.java 589ms 1.3ms 48.8MB 2057ms 23ms openjdk 23
java 2-m.java 709ms 1.6ms 45.4MB 2050ms 150ms openjdk/zgc 21
java 2-m.java 744ms 9.1ms 97.3MB 2500ms 47ms graal/jvm 17.0.8
nim 1.nim 895ms 0.6ms 1.5MB 883ms 0ms nim/clang 2.2.0
nim 1.nim 900ms 4.6ms 1.3MB 893ms 0ms nim 2.2.0

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 226ms 0.3ms 1.5MB 217ms 0ms nim/clang 2.2.0
nim 1.nim 228ms 2.2ms 1.3MB 220ms 0ms nim 2.2.0
java 2-m.java 240ms 8.9ms 48.7MB 707ms 20ms openjdk 23
java 2-m.java 247ms 10ms 47.6MB 713ms 27ms openjdk 21
java 2-m.java 276ms 6.0ms 98.1MB 780ms 40ms graal/jvm 17.0.8
java 2-m.java 383ms 12ms 45.4MB 743ms 150ms openjdk/zgc 21