Nim VS Java benchmarks

Current benchmark data was generated on Wed Feb 08 2023, full log can be found HERE

CONTRIBUTIONS are WELCOME!

[x86_64][2 cores] Intel(R) Xeon(R) Platinum 8171M 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 801ms 7.2ms 410.2MB 787ms 150ms openjdk 19
java 2.java 840ms 20ms 365.5MB 1003ms 133ms graal/jvm 17.0.6
java 2.java 855ms 43ms 607.0MB 807ms 183ms openjdk 20
java 2.java 1671ms 35ms 1188.8MB 1013ms 860ms openjdk/zgc 19
nim 2.nim 2517ms 18ms 33.9MB 2493ms 3ms nim 1.6.10
nim 2.nim 2531ms 9.3ms 34.8MB 2507ms 7ms nim/clang 1.6.10

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2.java 201ms 6.2ms 107.5MB 197ms 33ms openjdk 20
java 2.java 222ms 16ms 163.9MB 250ms 60ms graal/jvm 17.0.6
java 2.java 223ms 26ms 111.0MB 197ms 37ms openjdk 19
nim 2.nim 239ms 0.4ms 5.7MB 227ms 0ms nim/clang 1.6.10
nim 2.nim 240ms 1.4ms 5.5MB 220ms 0ms nim 1.6.10
java 2.java 383ms 9.9ms 238.2MB 210ms 197ms openjdk/zgc 19

coro-prime-sieve

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 3271ms 2834ms 943.0MB 8797ms 650ms openjdk/zgc 19
java 1-m.java 3881ms 18ms 198.6MB 7340ms 137ms openjdk 19
java 1.java timeout 0.0ms 139.8MB 9550ms 133ms openjdk 20
nim 1.nim timeout 0.0ms 405.0MB 3300ms 1353ms nim 1.6.10
nim 1.nim timeout 0.0ms 405.5MB 3347ms 1307ms nim/clang 1.6.10

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 874ms 43ms 113.0MB 1520ms 67ms openjdk 19
java 1-m.java 936ms 180ms 114.9MB 1630ms 63ms openjdk 20
java 1-m.java 1171ms 18ms 316.0MB 1860ms 250ms openjdk/zgc 19
nim 1.nim timeout 0.0ms 405.3MB 3357ms 1303ms nim 1.6.10
nim 1.nim timeout 0.0ms 407.5MB 3353ms 1290ms nim/clang 1.6.10

edigits

Input: 250001

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 865ms 18ms 199.9MB 1483ms 100ms openjdk 19
java 1-m.java 884ms 13ms 206.4MB 1543ms 77ms openjdk 20
java 1-m.java 925ms 47ms 251.2MB 1603ms 100ms graal/jvm 17.0.6
java 1-m.java 1201ms 4.1ms 447.1MB 1683ms 393ms openjdk/zgc 19
nim 1.nim timeout 0.0ms 3.1MB 4990ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 3.0MB 4983ms 0ms nim/clang 1.6.10

Input: 100000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 489ms 35ms 184.8MB 777ms 87ms graal/jvm 17.0.6
java 1-m.java 490ms 4.6ms 116.0MB 793ms 50ms openjdk 19
java 1-m.java 527ms 41ms 130.6MB 837ms 67ms openjdk 20
java 1-m.java 655ms 73ms 222.2MB 933ms 170ms openjdk/zgc 19
nim 1.nim timeout 0.0ms 2.3MB 4983ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 2.2MB 4980ms 0ms nim/clang 1.6.10

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 291ms 3.7ms 1.0MB 277ms 0ms nim 1.6.10
nim 2.nim 367ms 10.0ms 1.3MB 353ms 0ms nim/clang 1.6.10
java 4.java 554ms 15ms 40.1MB 633ms 23ms openjdk 20
java 4.java 564ms 18ms 41.4MB 653ms 13ms openjdk 19
java 4.java 621ms 18ms 42.0MB 637ms 83ms openjdk/zgc 19
java 4.java 646ms 8.9ms 101.0MB 870ms 50ms graal/jvm 17.0.6
nim 1.nim 823ms 13ms 1.3MB 707ms 97ms nim/clang 1.6.10
nim 1.nim 839ms 20ms 1.0MB 723ms 100ms nim 1.6.10

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 34ms 2.2ms 1.1MB 20ms 0ms nim 1.6.10
nim 2.nim 39ms 0.2ms 1.3MB 30ms 0ms nim/clang 1.6.10
nim 1.nim 84ms 1.5ms 1.2MB 63ms 7ms nim/clang 1.6.10
nim 1.nim 89ms 0.6ms 1.1MB 67ms 7ms nim 1.6.10
java 4.java 168ms 9.5ms 41.0MB 187ms 20ms openjdk 19
java 4.java 175ms 13ms 39.5MB 180ms 27ms openjdk 20
java 4.java 175ms 5.0ms 87.4MB 200ms 40ms graal/jvm 17.0.6
java 4.java 233ms 7.1ms 41.9MB 190ms 77ms openjdk/zgc 19

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 2.1ms 0.5ms 1.0MB 0ms 0ms nim 1.6.10
nim 1.nim 2.3ms 0.9ms 1.9MB 0ms 0ms nim/clang 1.6.10
java 1.java 92ms 4.3ms 65.3MB 88ms 14ms graal/jvm 17.0.6
java 1.java 93ms 5.9ms 42.0MB 84ms 14ms openjdk 19
java 1.java 96ms 8.2ms 39.1MB 92ms 16ms openjdk 20
java 1.java 158ms 14ms 41.4MB 84ms 82ms openjdk/zgc 19

http-server

Input: 3000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 954ms 7.7ms 94.1MB 447ms 470ms nim/clang 1.6.10
nim 1.nim 989ms 9.0ms 94.7MB 460ms 487ms nim 1.6.10

Input: 500

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 154ms 1.8ms 17.8MB 63ms 73ms nim 1.6.10
nim 1.nim 158ms 3.7ms 18.1MB 60ms 83ms nim/clang 1.6.10

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 180ms 1.4ms 1.3MB 170ms 0ms nim/clang 1.6.10
nim 2.nim 184ms 1.5ms 1.0MB 170ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 1.1MB 4983ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 1.2MB 4987ms 0ms nim/clang 1.6.10

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 535ms 14ms 1.3MB 520ms 0ms nim/clang 1.6.10
nim 2.nim 540ms 0.9ms 1.1MB 530ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 1.0MB 4990ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 1.3MB 4983ms 0ms nim/clang 1.6.10

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 77ms 2.3ms 1.2MB 67ms 0ms nim/clang 1.6.10
nim 2.nim 80ms 1.7ms 1.0MB 70ms 0ms nim 1.6.10
nim 1.nim 449ms 7.2ms 1.3MB 437ms 0ms nim/clang 1.6.10
nim 1.nim 496ms 1.6ms 1.0MB 483ms 0ms nim 1.6.10

mandelbrot

Input: 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 697ms 0.6ms 4.8MB 687ms 0ms nim/clang 1.6.10
nim 1.nim 1040ms 3.5ms 4.4MB 1030ms 0ms nim 1.6.10
java 1b.java 1780ms 4.4ms 49.7MB 1863ms 27ms openjdk 19
java 1b.java 1821ms 5.4ms 47.2MB 1957ms 20ms openjdk 20
java 1b.java 1846ms 20ms 47.4MB 1880ms 93ms openjdk/zgc 19
java 1b.java 1906ms 42ms 109.9MB 2140ms 30ms graal/jvm 17.0.6
java 1a.java 2153ms 5.7ms 47.2MB 2237ms 23ms openjdk 20
java 1a.java 2167ms 23ms 50.3MB 2267ms 17ms openjdk 19
java 1a.java 2184ms 25ms 47.5MB 2187ms 80ms openjdk/zgc 19
java 1a.java 2198ms 8.5ms 100.4MB 2303ms 43ms graal/jvm 17.0.6
java 1.java 2344ms 39ms 202.5MB 2337ms 90ms openjdk 19
java 1.java 2433ms 6.6ms 136.8MB 2523ms 53ms graal/jvm 17.0.6
java 1.java 2533ms 189ms 197.6MB 2570ms 90ms openjdk 20
java 1.java 2792ms 11ms 581.4MB 2397ms 507ms openjdk/zgc 19
java 2.java timeout 0.0ms 547.5MB 5130ms 190ms openjdk 19
java 2.java timeout 0.0ms 622.3MB 5130ms 200ms openjdk 20
java 2.java timeout 0.0ms 1703.0MB 4407ms 1023ms openjdk/zgc 19

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 33ms 0.4ms 1.3MB 20ms 0ms nim/clang 1.6.10
nim 1.nim 49ms 1.0ms 1.0MB 40ms 0ms nim 1.6.10
java 1b.java 254ms 4.7ms 42.7MB 330ms 27ms openjdk 20
java 1.java 269ms 7.9ms 95.4MB 293ms 33ms openjdk 19
java 1a.java 271ms 10ms 47.1MB 333ms 27ms openjdk 19
java 1.java 272ms 7.2ms 96.3MB 293ms 43ms openjdk 20
java 1b.java 274ms 17ms 46.2MB 370ms 20ms openjdk 19
java 1a.java 278ms 5.8ms 43.0MB 363ms 23ms openjdk 20
java 1.java 289ms 8.7ms 100.2MB 377ms 33ms graal/jvm 17.0.6
java 1a.java 294ms 29ms 96.8MB 377ms 23ms graal/jvm 17.0.6
java 1a.java 308ms 6.5ms 44.3MB 290ms 80ms openjdk/zgc 19
java 1b.java 329ms 14ms 44.1MB 363ms 80ms openjdk/zgc 19
java 1b-m.java 335ms 40ms 99.2MB 490ms 40ms graal/jvm 17.0.6
java 1.java 357ms 10ms 110.9MB 293ms 130ms openjdk/zgc 19
java 2.java 929ms 43ms 557.5MB 1113ms 163ms openjdk 19
java 2.java 942ms 50ms 623.7MB 1097ms 203ms openjdk 20
java 2.java 1818ms 149ms 1243.8MB 1233ms 897ms openjdk/zgc 19

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 638ms 8.3ms 288.6MB 647ms 103ms openjdk 20
java 1.java 654ms 15ms 368.8MB 683ms 97ms openjdk 19
java 1.java 677ms 7.2ms 345.2MB 840ms 140ms graal/jvm 17.0.6
java 1.java 1201ms 20ms 760.4MB 800ms 567ms openjdk/zgc 19
nim 1.nim 1276ms 2.5ms 35.1MB 1243ms 10ms nim/clang 1.6.10
nim 1.nim 1294ms 0.4ms 34.6MB 1267ms 7ms nim 1.6.10

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 262ms 3.6ms 173.9MB 293ms 40ms openjdk 19
nim 1.nim 275ms 0.8ms 9.3MB 260ms 0ms nim 1.6.10
nim 1.nim 275ms 4.2ms 9.5MB 260ms 0ms nim/clang 1.6.10
java 1.java 286ms 5.3ms 222.6MB 287ms 67ms openjdk 20
java 1-m.java 345ms 9.1ms 280.6MB 463ms 87ms graal/jvm 17.0.6
java 1.java 513ms 64ms 321.3MB 320ms 237ms openjdk/zgc 19

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 489ms 4.9ms 1.2MB 477ms 0ms nim/clang 1.6.10
nim 2.nim 489ms 14ms 1.3MB 477ms 0ms nim 1.6.10
java 1.java 688ms 13ms 89.8MB 730ms 17ms graal/jvm 17.0.6
java 1.java 755ms 7.1ms 40.4MB 757ms 27ms openjdk 20
java 1.java 764ms 8.1ms 43.4MB 763ms 23ms openjdk 19
java 1.java 846ms 17ms 44.4MB 793ms 80ms openjdk/zgc 19
java 2.java 2324ms 28ms 656.4MB 2277ms 213ms openjdk 20
java 2.java 2338ms 11ms 550.4MB 2307ms 183ms openjdk 19
java 2.java 3688ms 40ms 1609.1MB 2637ms 1277ms openjdk/zgc 19

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 52ms 1.6ms 1.3MB 43ms 0ms nim 1.6.10
nim 2.nim 53ms 2.1ms 1.2MB 40ms 0ms nim/clang 1.6.10
java 1.java 180ms 4.4ms 89.8MB 207ms 33ms graal/jvm 17.0.6
java 1.java 184ms 8.6ms 40.5MB 193ms 17ms openjdk 20
java 1.java 188ms 4.0ms 43.6MB 197ms 17ms openjdk 19
java 1.java 247ms 5.2ms 42.4MB 193ms 83ms openjdk/zgc 19
java 2.java 511ms 7.9ms 354.7MB 550ms 113ms openjdk 20
java 2.java 520ms 20ms 355.3MB 567ms 123ms openjdk 19
java 2.java 890ms 59ms 506.8MB 663ms 393ms openjdk/zgc 19

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 782ms 1.9ms 6.3MB 770ms 0ms nim/clang 1.6.10
nim 2.nim 988ms 18ms 6.0MB 973ms 0ms nim 1.6.10
nim 1.nim 1048ms 48ms 41.3MB 1023ms 10ms nim/clang 1.6.10
nim 1.nim 1053ms 31ms 40.6MB 1027ms 7ms nim 1.6.10
java 2.java 1197ms 8.4ms 50.4MB 1237ms 20ms openjdk 20
java 1.java 1211ms 11ms 84.4MB 1233ms 30ms openjdk 19
java 1.java 1227ms 46ms 84.6MB 1247ms 40ms openjdk 20
java 2.java 1260ms 8.6ms 53.6MB 1313ms 13ms openjdk 19
java 2.java 1326ms 4.8ms 52.5MB 1300ms 87ms openjdk/zgc 19
java 1.java 1425ms 29ms 110.6MB 1363ms 120ms openjdk/zgc 19
java 1.java 1684ms 26ms 239.6MB 2347ms 127ms graal/jvm 17.0.6
java 2-m.java 2194ms 21ms 206.3MB 3857ms 123ms graal/jvm 17.0.6

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 153ms 1.5ms 11.1MB 140ms 0ms nim 1.6.10
nim 1.nim 156ms 2.8ms 11.3MB 140ms 0ms nim/clang 1.6.10
nim 2.nim 174ms 4.5ms 3.2MB 163ms 0ms nim/clang 1.6.10
nim 2.nim 240ms 7.1ms 3.1MB 230ms 0ms nim 1.6.10
java 1.java 277ms 2.7ms 58.4MB 297ms 27ms openjdk 20
java 1.java 285ms 2.3ms 59.6MB 293ms 37ms openjdk 19
java 1.java 363ms 18ms 60.8MB 327ms 97ms openjdk/zgc 19
java 2.java 378ms 7.9ms 45.1MB 420ms 13ms openjdk 20
java 2.java 401ms 11ms 50.0MB 427ms 23ms openjdk 19
java 1.java 401ms 13ms 121.8MB 540ms 60ms graal/jvm 17.0.6
java 2.java 465ms 9.2ms 44.2MB 430ms 87ms openjdk/zgc 19
java 2-m.java 786ms 5.5ms 148.8MB 1357ms 80ms graal/jvm 17.0.6

pidigits

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java timeout 0.0ms 300.8MB 5513ms 140ms graal/jvm 17.0.6
java 1.java timeout 0.0ms 294.4MB 5513ms 110ms openjdk 19
java 1.java timeout 0.0ms 316.4MB 5490ms 117ms openjdk 20
java 1.java timeout 0.0ms 1383.4MB 4503ms 940ms openjdk/zgc 19
nim 1.nim timeout 0.0ms 5.6MB 4990ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 5.8MB 4987ms 0ms nim/clang 1.6.10

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 1642ms 22ms 304.2MB 2007ms 103ms openjdk 19
java 1.java 1642ms 26ms 291.3MB 1927ms 90ms openjdk 20
java 1.java 1766ms 11ms 315.8MB 2257ms 120ms graal/jvm 17.0.6
java 1.java 2312ms 22ms 1045.8MB 1943ms 863ms openjdk/zgc 19
nim 1.nim timeout 0.0ms 5.6MB 4983ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 5.8MB 4990ms 0ms nim/clang 1.6.10

regex-redux

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 2873ms 14ms 168.2MB 2813ms 40ms nim/clang 1.6.10
nim 1.nim 2937ms 11ms 166.9MB 2870ms 50ms nim 1.6.10
java 3.java timeout 0.0ms 251.6MB 5393ms 100ms graal/jvm 17.0.6
java 3.java timeout 0.0ms 208.2MB 5320ms 77ms openjdk 19
java 3.java timeout 0.0ms 204.2MB 5303ms 73ms openjdk 20
java 3.java timeout 0.0ms 335.7MB 4947ms 290ms openjdk/zgc 19

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 295ms 9.2ms 17.1MB 277ms 3ms nim/clang 1.6.10
nim 1.nim 299ms 3.5ms 16.7MB 280ms 0ms nim 1.6.10
java 3.java 1186ms 15ms 111.3MB 1563ms 53ms openjdk 19
java 3.java 1196ms 24ms 169.4MB 1687ms 60ms graal/jvm 17.0.6
java 3.java 1201ms 11ms 112.5MB 1597ms 50ms openjdk 20
java 3.java 1337ms 14ms 159.1MB 1487ms 187ms openjdk/zgc 19

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 4075ms 23ms 1.2MB 4060ms 0ms nim/clang 1.6.10
nim 1.nim 4100ms 19ms 1.3MB 4087ms 0ms nim 1.6.10
java 2.java timeout 0.0ms 91.1MB 9620ms 57ms graal/jvm 17.0.6
java 2.java timeout 0.0ms 44.6MB 9673ms 23ms openjdk 19
java 2.java timeout 0.0ms 40.7MB 9670ms 23ms openjdk 20
java 2.java timeout 0.0ms 44.1MB 9580ms 63ms openjdk/zgc 19

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 1028ms 4.7ms 1.3MB 1020ms 0ms nim 1.6.10
nim 1.nim 1040ms 16ms 1.2MB 1027ms 0ms nim/clang 1.6.10
java 2-m.java 1423ms 72ms 91.9MB 2637ms 30ms graal/jvm 17.0.6
java 2-m.java 2021ms 51ms 41.9MB 3780ms 30ms openjdk 19
java 2-m.java 2159ms 141ms 43.9MB 3967ms 80ms openjdk/zgc 19
java 2-m.java 2484ms 111ms 40.8MB 4717ms 20ms openjdk 20

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 261ms 1.5ms 1.2MB 250ms 0ms nim/clang 1.6.10
nim 1.nim 262ms 2.0ms 1.3MB 250ms 0ms nim 1.6.10
java 2-m.java 505ms 14ms 93.3MB 827ms 33ms graal/jvm 17.0.6
java 2-m.java 685ms 36ms 43.9MB 1207ms 23ms openjdk 19
java 2-m.java 719ms 39ms 42.2MB 1160ms 83ms openjdk/zgc 19
java 2-m.java 801ms 105ms 41.1MB 1323ms 20ms openjdk 20