OCaml VS C++ benchmarks

Current benchmark data was generated on Mon Jun 23 2025, 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
ocaml 1.ml 3028ms 44ms 157.2MB 2940ms 73ms ocaml 5.3.0

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 214ms 0.9ms 19.1MB 200ms 0ms ocaml 5.3.0

fannkuch-redux

Input: 11

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1-im.cpp 395ms 6.0ms 2.6MB 1533ms 0ms g++ 11.4.0
cpp 1-im.cpp 402ms 7.0ms 3.9MB 1557ms 0ms clang++ 14.0.0-1ubuntu1.1
ocaml 2.ml 2914ms 16ms 4.9MB 2907ms 0ms ocaml 5.3.0

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1-im.cpp 39ms 0.3ms 2.6MB 130ms 0ms g++ 11.4.0
cpp 1-im.cpp 42ms 1.6ms 4.0MB 133ms 0ms clang++ 14.0.0-1ubuntu1.1
ocaml 2.ml 245ms 3.3ms 4.9MB 237ms 0ms ocaml 5.3.0

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 6.ml 347ms 1.7ms 24.8MB 337ms 0ms ocaml 5.3.0

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 6.ml 39ms 0.5ms 7.5MB 30ms 0ms ocaml 5.3.0

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1.cpp 1.0ms 0.0ms 1.4MB 0ms 0ms g++ 11.4.0
cpp 1.cpp 1.4ms 0.2ms 2.3MB 0ms 0ms clang++ 14.0.0-1ubuntu1.1
ocaml 1.ml 1.8ms 0.2ms 5.0MB 0ms 0ms ocaml 5.3.0

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 190ms 0.6ms 6.4MB 180ms 0ms ocaml 5.3.0

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 518ms 3.2ms 6.6MB 510ms 0ms ocaml 5.3.0

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 77ms 1.4ms 5.9MB 70ms 0ms ocaml 5.3.0

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 1094ms 11ms 70.2MB 1047ms 30ms ocaml 5.3.0
ocaml 2.ml 2066ms 16ms 91.8MB 2013ms 33ms ocaml 5.3.0

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 147ms 4.1ms 21.7MB 130ms 7ms ocaml 5.3.0
ocaml 2.ml 367ms 7.6ms 27.7MB 343ms 7ms ocaml 5.3.0

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 167ms 0.4ms 1.5MB 160ms 0ms g++ 11.4.0
cpp 0-i.cpp 172ms 0.2ms 2.3MB 160ms 0ms clang++ 14.0.0-1ubuntu1.1
cpp 1.cpp 316ms 2.1ms 1.9MB 307ms 0ms g++ 11.4.0
cpp 1.cpp 320ms 4.3ms 2.3MB 313ms 0ms clang++ 14.0.0-1ubuntu1.1
ocaml 1.ml 373ms 1.9ms 5.2MB 360ms 0ms ocaml 5.3.0

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 19ms 0.1ms 1.5MB 10ms 0ms g++ 11.4.0
cpp 0-i.cpp 19ms 0.2ms 2.3MB 10ms 0ms clang++ 14.0.0-1ubuntu1.1
cpp 1.cpp 34ms 0.5ms 2.3MB 30ms 0ms clang++ 14.0.0-1ubuntu1.1
cpp 1.cpp 34ms 0.5ms 1.8MB 30ms 0ms g++ 11.4.0
ocaml 1.ml 41ms 1.4ms 5.2MB 30ms 0ms ocaml 5.3.0

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1.cpp 483ms 1.2ms 7.3MB 477ms 0ms g++ 11.4.0
cpp 1.cpp 531ms 2.7ms 7.8MB 520ms 0ms clang++ 14.0.0-1ubuntu1.1
ocaml 1.ml 957ms 3.4ms 550.3MB 900ms 43ms ocaml 5.3.0
ocaml 2.ml 1886ms 14ms 18.9MB 1873ms 0ms ocaml 5.3.0

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1.cpp 121ms 1.0ms 3.6MB 110ms 0ms g++ 11.4.0
cpp 1.cpp 133ms 0.6ms 4.1MB 127ms 0ms clang++ 14.0.0-1ubuntu1.1
ocaml 1.ml 191ms 3.0ms 141.6MB 170ms 10ms ocaml 5.3.0
ocaml 2.ml 471ms 4.3ms 9.1MB 460ms 0ms ocaml 5.3.0

regex-redux

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 2.ml timeout 0.0ms 462.9MB 4830ms 153ms ocaml 5.3.0

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 2.ml 549ms 4.5ms 57.1MB 513ms 23ms ocaml 5.3.0

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 8-m.cpp 468ms 0.9ms 3.5MB 1820ms 0ms clang++ 14.0.0-1ubuntu1.1
cpp 8-m.cpp 493ms 18ms 2.1MB 1913ms 0ms g++ 11.4.0
cpp 6-im.cpp 927ms 13ms 2.1MB 3633ms 0ms g++ 11.4.0
cpp 6-im.cpp 952ms 38ms 3.5MB 3693ms 3ms clang++ 14.0.0-1ubuntu1.1
ocaml 2.ml 4582ms 24ms 6.4MB 4570ms 0ms ocaml 5.3.0

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 8-m.cpp 123ms 0.3ms 3.3MB 457ms 0ms clang++ 14.0.0-1ubuntu1.1
cpp 8-m.cpp 129ms 0.4ms 2.0MB 480ms 0ms g++ 11.4.0
cpp 6-im.cpp 238ms 0.6ms 3.4MB 900ms 0ms clang++ 14.0.0-1ubuntu1.1
cpp 6-im.cpp 239ms 1.1ms 2.0MB 920ms 0ms g++ 11.4.0
ocaml 2.ml 1159ms 5.5ms 6.1MB 1150ms 0ms ocaml 5.3.0

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 8-m.cpp 39ms 0.2ms 2.0MB 130ms 0ms g++ 11.4.0
cpp 8-m.cpp 46ms 13ms 3.4MB 127ms 0ms clang++ 14.0.0-1ubuntu1.1
cpp 6-im.cpp 66ms 0.5ms 3.4MB 223ms 0ms clang++ 14.0.0-1ubuntu1.1
cpp 6-im.cpp 67ms 0.6ms 2.1MB 240ms 0ms g++ 11.4.0
ocaml 2.ml 294ms 4.6ms 5.2MB 283ms 0ms ocaml 5.3.0