OCaml VS Java benchmarks

Current benchmark data was generated on Thu Sep 22 2022, full log can be found HERE

CONTRIBUTIONS are WELCOME!

[x86_64][2 cores] Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz (Model 106)

* -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 664ms 1.0ms 413.9MB 690ms 83ms openjdk 20
java 2.java 690ms 43ms 602.5MB 673ms 120ms openjdk 19
java 2.java 744ms 45ms 680.0MB 807ms 163ms graal/jvm 17.0.4
java 2.java 1277ms 28ms 1069.2MB 903ms 583ms openjdk/zgc 19
ocaml 1.ml 3969ms 9.3ms 121.0MB 3927ms 23ms ocaml 4.14.0

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2.java 164ms 6.4ms 109.4MB 170ms 23ms openjdk 19
java 2.java 174ms 14ms 111.4MB 163ms 37ms openjdk 20
java 2-m.java 182ms 6.2ms 168.4MB 240ms 40ms graal/jvm 17.0.4
ocaml 1.ml 271ms 1.1ms 17.4MB 250ms 3ms ocaml 4.14.0
java 2.java 300ms 5.7ms 243.7MB 187ms 153ms openjdk/zgc 19

fannkuch-redux

Input: 11

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 1676ms 23ms 100.6MB 3180ms 33ms graal/jvm 17.0.4
java 1-m.java 1702ms 47ms 43.8MB 3257ms 17ms openjdk 20
java 1-m.java 1722ms 18ms 43.8MB 3290ms 13ms openjdk 19
java 1-m.java 1731ms 12ms 42.4MB 3233ms 50ms openjdk/zgc 19
ocaml 2.ml 3940ms 31ms 2.5MB 3927ms 0ms ocaml 4.14.0

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 272ms 3.4ms 42.5MB 443ms 13ms openjdk 20
java 1-m.java 273ms 6.2ms 42.2MB 437ms 10ms openjdk 19
java 1-m.java 285ms 13ms 91.6MB 450ms 17ms graal/jvm 17.0.4
java 1-m.java 315ms 4.4ms 42.5MB 450ms 50ms openjdk/zgc 19
ocaml 2.ml 326ms 0.7ms 2.6MB 313ms 0ms ocaml 4.14.0

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 6.ml 423ms 2.2ms 23.9MB 403ms 0ms ocaml 4.14.0
java 4.java 510ms 2.3ms 44.0MB 587ms 17ms openjdk 20
java 4.java 515ms 7.4ms 43.3MB 590ms 17ms openjdk 19
java 4.java 558ms 6.8ms 41.8MB 587ms 67ms openjdk/zgc 19
java 4-m.java 618ms 4.2ms 119.8MB 937ms 27ms graal/jvm 17.0.4

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 6.ml 49ms 3.5ms 4.8MB 37ms 0ms ocaml 4.14.0
java 4.java 141ms 1.4ms 42.9MB 160ms 20ms openjdk 20
java 4.java 144ms 4.0ms 41.2MB 177ms 7ms openjdk 19
java 4.java 154ms 7.2ms 90.9MB 193ms 23ms graal/jvm 17.0.4
java 4.java 184ms 4.4ms 43.1MB 167ms 50ms openjdk/zgc 19

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 1.9ms 0.5ms 2.5MB 0ms 0ms ocaml 4.14.0
java 1.java 70ms 3.1ms 63.4MB 70ms 10ms graal/jvm 17.0.4
java 1.java 78ms 5.0ms 42.7MB 78ms 6ms openjdk 20
java 1.java 82ms 3.6ms 40.8MB 78ms 8ms openjdk 19
java 1.java 119ms 4.8ms 39.9MB 78ms 52ms openjdk/zgc 19

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 238ms 0.5ms 5.9MB 227ms 0ms ocaml 4.14.0

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 707ms 1.5ms 5.8MB 693ms 0ms ocaml 4.14.0

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 104ms 0.4ms 5.1MB 90ms 0ms ocaml 4.14.0

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 495ms 5.0ms 291.5MB 513ms 73ms openjdk 20
java 1.java 512ms 13ms 367.3MB 520ms 83ms openjdk 19
java 1.java 549ms 9.4ms 361.3MB 697ms 87ms graal/jvm 17.0.4
java 1.java 932ms 20ms 758.5MB 643ms 430ms openjdk/zgc 19
ocaml 1.ml 1503ms 5.0ms 62.6MB 1460ms 23ms ocaml 4.14.0
ocaml 2.ml 2552ms 7.6ms 71.4MB 2520ms 20ms ocaml 4.14.0

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 192ms 0.9ms 18.6MB 177ms 0ms ocaml 4.14.0
java 1.java 219ms 2.1ms 173.3MB 243ms 37ms openjdk 19
java 1.java 223ms 6.1ms 174.3MB 237ms 43ms openjdk 20
java 1-m.java 267ms 8.9ms 245.9MB 380ms 60ms graal/jvm 17.0.4
ocaml 2.ml 430ms 3.0ms 23.6MB 410ms 3ms ocaml 4.14.0
java 1.java 433ms 6.0ms 353.0MB 260ms 230ms openjdk/zgc 19

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 470ms 0.2ms 2.6MB 460ms 0ms ocaml 4.14.0
java 1.java 539ms 2.8ms 86.1MB 583ms 20ms graal/jvm 17.0.4
java 1.java 558ms 2.9ms 44.4MB 563ms 23ms openjdk 20
java 1.java 558ms 2.6ms 42.4MB 577ms 13ms openjdk 19
java 1.java 614ms 4.4ms 42.3MB 590ms 57ms openjdk/zgc 19
java 2.java 1887ms 33ms 538.3MB 1923ms 107ms openjdk 19
java 2.java 1923ms 9.6ms 563.7MB 1950ms 127ms openjdk 20
java 2.java 2582ms 4.7ms 1219.4MB 2027ms 753ms openjdk/zgc 19

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 52ms 3.8ms 2.6MB 40ms 0ms ocaml 4.14.0
java 1.java 142ms 3.9ms 42.7MB 157ms 17ms openjdk 20
java 1.java 144ms 1.6ms 86.4MB 190ms 20ms graal/jvm 17.0.4
java 1.java 146ms 5.8ms 42.7MB 167ms 10ms openjdk 19
java 1.java 190ms 3.5ms 42.2MB 160ms 57ms openjdk/zgc 19
java 2.java 414ms 4.9ms 363.3MB 493ms 70ms openjdk 20
java 2.java 417ms 2.1ms 355.0MB 483ms 73ms openjdk 19
java 2.java 676ms 0.7ms 455.4MB 547ms 290ms openjdk/zgc 19

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 781ms 22ms 88.1MB 807ms 23ms openjdk 20
java 1.java 922ms 29ms 84.4MB 943ms 23ms openjdk 19
java 1.java 982ms 26ms 110.6MB 940ms 87ms openjdk/zgc 19
java 2.java 1003ms 4.6ms 52.7MB 1043ms 13ms openjdk 20
java 2.java 1028ms 5.3ms 52.2MB 1010ms 60ms openjdk/zgc 19
java 2.java 1039ms 37ms 54.3MB 1077ms 17ms openjdk 19
java 1-m.java 1472ms 70ms 163.9MB 2240ms 53ms graal/jvm 17.0.4
java 2-m.java 1848ms 24ms 128.2MB 3400ms 50ms graal/jvm 17.0.4
ocaml 1.ml 1976ms 10ms 555.7MB 1877ms 87ms ocaml 4.14.0
ocaml 2.ml 2265ms 1.2ms 19.9MB 2247ms 0ms ocaml 4.14.0

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 236ms 2.7ms 62.5MB 270ms 13ms openjdk 20
java 1.java 237ms 4.6ms 62.3MB 257ms 27ms openjdk 19
java 1.java 280ms 5.4ms 60.9MB 263ms 60ms openjdk/zgc 19
java 2.java 325ms 6.4ms 48.8MB 363ms 10ms openjdk 20
java 2.java 326ms 0.8ms 48.2MB 360ms 17ms openjdk 19
java 1-m.java 332ms 8.9ms 135.3MB 470ms 43ms graal/jvm 17.0.4
java 2.java 360ms 3.3ms 44.2MB 353ms 50ms openjdk/zgc 19
ocaml 1.ml 390ms 10ms 142.6MB 353ms 20ms ocaml 4.14.0
ocaml 2.ml 551ms 4.1ms 9.5MB 537ms 0ms ocaml 4.14.0
java 2-m.java 611ms 3.6ms 127.9MB 1100ms 33ms graal/jvm 17.0.4

regex-redux

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 3.java timeout 0.0ms 0.0MB 0ms 0ms graal/jvm 17.0.4
java 3.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 19
java 3.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 20
java 3.java timeout 0.0ms 0.0MB 0ms 0ms openjdk/zgc 19
ocaml 2.ml timeout 0.0ms 0.0MB 0ms 0ms ocaml 4.14.0

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 2.ml 683ms 0.6ms 50.4MB 657ms 10ms ocaml 4.14.0
java 3.java 1050ms 10ms 187.5MB 1453ms 50ms graal/jvm 17.0.4
java 3.java 1073ms 14ms 112.0MB 1417ms 40ms openjdk 20
java 3.java 1079ms 23ms 109.8MB 1417ms 43ms openjdk 19
java 3.java 1166ms 16ms 158.0MB 1343ms 123ms openjdk/zgc 19

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2-m.java 4306ms 8.2ms 104.9MB 8330ms 30ms 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
ocaml 2.ml timeout 0.0ms 0.0MB 0ms 0ms ocaml 4.14.0

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2-m.java 1270ms 5.6ms 108.9MB 2323ms 37ms graal/jvm 17.0.4
ocaml 2.ml 1645ms 0.1ms 3.4MB 1633ms 0ms ocaml 4.14.0
java 2-m.java 1647ms 83ms 44.4MB 3100ms 20ms openjdk 19
java 2-m.java 1733ms 180ms 44.2MB 3290ms 17ms openjdk 20
java 2-m.java 1755ms 197ms 42.6MB 3250ms 57ms openjdk/zgc 19

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 2.ml 415ms 0.7ms 3.1MB 400ms 0ms ocaml 4.14.0
java 2-m.java 446ms 11ms 98.3MB 743ms 40ms graal/jvm 17.0.4
java 2-m.java 563ms 42ms 44.2MB 1017ms 10ms openjdk 20
java 2-m.java 582ms 12ms 44.6MB 1037ms 17ms openjdk 19
java 2-m.java 647ms 16ms 44.4MB 1083ms 50ms openjdk/zgc 19