OCaml VS Python 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
python 1.py 1191ms 15ms 96.3MB 1123ms 53ms pypy 3.10.16
ocaml 1.ml 3028ms 44ms 157.2MB 2940ms 73ms ocaml 5.3.0
python 1.py timeout 0.0ms 41.0MB 4973ms 17ms cpython 3.13.5
python 1.py timeout 0.0ms 40.5MB 4750ms 230ms pyston 3.8.12

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 101ms 1.2ms 68.6MB 67ms 20ms pypy 3.10.16
ocaml 1.ml 214ms 0.9ms 19.1MB 200ms 0ms ocaml 5.3.0
python 1.py 476ms 3.1ms 11.9MB 453ms 10ms pyston 3.8.12
python 1.py 734ms 12ms 13.0MB 723ms 0ms cpython 3.13.5

fannkuch-redux

Input: 11

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
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
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
python 1.py 1867ms 5.3ms 88.9MB 1820ms 33ms pypy 3.10.16
python 5-m.py 2287ms 10ms 65.6MB 3470ms 880ms pypy 3.10.16
python 5-m.py 2582ms 230ms 12.5MB 3513ms 1153ms pyston 3.8.12
python 1.py 3033ms 32ms 8.1MB 3020ms 0ms pyston 3.8.12
python 5-m.py 3368ms 22ms 13.9MB 4457ms 910ms cpython 3.13.5
python 1.py 4740ms 91ms 9.0MB 4727ms 0ms cpython 3.13.5

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
python 1.py 255ms 1.5ms 63.4MB 223ms 17ms pypy 3.10.16
python 5-m.py 310ms 1.8ms 12.5MB 400ms 140ms pyston 3.8.12
python 1.py 314ms 0.6ms 8.1MB 300ms 0ms pyston 3.8.12
python 5-m.py 402ms 9.2ms 13.9MB 490ms 130ms cpython 3.13.5
python 5-m.py 450ms 6.4ms 65.6MB 747ms 310ms pypy 3.10.16
python 1.py 494ms 21ms 8.9MB 483ms 0ms cpython 3.13.5

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 1.8ms 0.2ms 5.0MB 0ms 0ms ocaml 5.3.0
python 1.py 11ms 0.5ms 7.6MB 0ms 0ms pyston 3.8.12
python 1.py 14ms 1.1ms 8.9MB 0ms 0ms cpython 3.13.5
python 1.py 29ms 1.3ms 51.7MB 10ms 10ms pypy 3.10.16

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 2.py 148ms 3.7ms 58.4MB 123ms 10ms pypy 3.10.16
python 1.py 182ms 4.5ms 59.4MB 160ms 10ms pypy 3.10.16
ocaml 1.ml 190ms 0.6ms 6.4MB 180ms 0ms ocaml 5.3.0
python 1.py 742ms 13ms 8.9MB 730ms 0ms pyston 3.8.12
python 2.py 861ms 17ms 8.5MB 850ms 0ms pyston 3.8.12
python 1.py 1135ms 8.0ms 9.5MB 1120ms 0ms cpython 3.13.5
python 2.py 1359ms 9.5ms 9.4MB 1347ms 0ms cpython 3.13.5

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 2.py 340ms 3.5ms 59.4MB 317ms 10ms pypy 3.10.16
python 1.py 378ms 4.8ms 60.3MB 353ms 13ms pypy 3.10.16
ocaml 1.ml 518ms 3.2ms 6.6MB 510ms 0ms ocaml 5.3.0
python 1.py 2158ms 21ms 8.9MB 2147ms 0ms pyston 3.8.12
python 2.py 2527ms 78ms 8.5MB 2513ms 0ms pyston 3.8.12
python 1.py 3383ms 12ms 9.5MB 3370ms 0ms cpython 3.13.5
python 2.py 3989ms 100ms 9.3MB 3973ms 0ms cpython 3.13.5

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
python 2.py 107ms 0.7ms 58.2MB 80ms 13ms pypy 3.10.16
python 1.py 121ms 2.3ms 58.8MB 100ms 10ms pypy 3.10.16
python 1.py 356ms 7.7ms 8.5MB 343ms 0ms pyston 3.8.12
python 2.py 388ms 3.7ms 8.1MB 377ms 0ms pyston 3.8.12
python 1.py 542ms 5.2ms 9.4MB 530ms 0ms cpython 3.13.5
python 2.py 648ms 0.8ms 8.9MB 637ms 0ms cpython 3.13.5

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
python 1.py 2233ms 15ms 202.7MB 2127ms 97ms pypy 3.10.16
python 1.py timeout 0.0ms 94.1MB 4957ms 33ms cpython 3.13.5
python 1.py timeout 0.0ms 130.4MB 4937ms 50ms pyston 3.8.12

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
python 1.py 385ms 7.0ms 104.8MB 327ms 43ms pypy 3.10.16
python 1.py 3165ms 60ms 37.3MB 3140ms 13ms cpython 3.13.5
python 1.py timeout 0.0ms 48.9MB 4963ms 23ms pyston 3.8.12

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 373ms 1.9ms 5.2MB 360ms 0ms ocaml 5.3.0
python 2.py 1361ms 5.0ms 57.9MB 1333ms 10ms pypy 3.10.16
python 1.py 2654ms 8.4ms 58.4MB 2627ms 10ms pypy 3.10.16
python 1.py timeout 0.0ms 9.0MB 4990ms 0ms cpython 3.13.5
python 2.py timeout 0.0ms 9.0MB 4990ms 0ms cpython 3.13.5
python 1.py timeout 0.0ms 8.3MB 4990ms 0ms pyston 3.8.12
python 2.py timeout 0.0ms 8.1MB 4990ms 0ms pyston 3.8.12

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 41ms 1.4ms 5.2MB 30ms 0ms ocaml 5.3.0
python 2.py 180ms 2.2ms 58.2MB 157ms 10ms pypy 3.10.16
python 1.py 306ms 6.8ms 57.2MB 283ms 10ms pypy 3.10.16
python 1.py 943ms 6.5ms 8.3MB 933ms 0ms pyston 3.8.12
python 2.py 1324ms 11ms 8.1MB 1313ms 0ms pyston 3.8.12
python 1.py 2929ms 30ms 9.0MB 2917ms 0ms cpython 3.13.5
python 2.py 2959ms 13ms 9.0MB 2947ms 0ms cpython 3.13.5

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
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
python 1.py 2598ms 50ms 369.6MB 2527ms 57ms pypy 3.10.16
python 2.py 3047ms 54ms 632.9MB 2860ms 173ms pyston 3.8.12
python 1.py 4792ms 40ms 320.4MB 4733ms 43ms pyston 3.8.12
python 1.py timeout 0.0ms 321.4MB 4960ms 20ms cpython 3.13.5
python 2.py timeout 0.0ms 633.8MB 4817ms 173ms cpython 3.13.5
python 2.py timeout 0.0ms 960.0MB 4707ms 283ms pypy 3.10.16

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
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
python 1.py 555ms 7.1ms 135.3MB 520ms 20ms pypy 3.10.16
python 2.py 736ms 10.0ms 164.3MB 693ms 30ms pyston 3.8.12
python 1.py 1099ms 37ms 86.0MB 1077ms 10ms pyston 3.8.12
python 2.py 1419ms 19ms 165.1MB 1373ms 33ms cpython 3.13.5
python 2.py 1579ms 52ms 290.2MB 1487ms 77ms pypy 3.10.16
python 1.py 2896ms 26ms 87.0MB 2870ms 10ms cpython 3.13.5

regex-redux

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 2259ms 23ms 243.6MB 2197ms 50ms pypy 3.10.16
python 1.py 4762ms 13ms 226.3MB 4560ms 190ms pyston 3.8.12
ocaml 2.ml timeout 0.0ms 462.9MB 4830ms 153ms ocaml 5.3.0
python 1.py timeout 0.0ms 137.2MB 4933ms 50ms cpython 3.13.5

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 337ms 3.6ms 86.0MB 297ms 27ms pypy 3.10.16
python 1.py 502ms 4.6ms 30.5MB 467ms 20ms pyston 3.8.12
ocaml 2.ml 549ms 4.5ms 57.1MB 513ms 23ms ocaml 5.3.0
python 1.py 619ms 1.3ms 30.1MB 587ms 20ms cpython 3.13.5

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 2.ml 4582ms 24ms 6.4MB 4570ms 0ms ocaml 5.3.0
python 8.py timeout 0.0ms 14.8MB 40ms 10ms cpython 3.13.5
python 8.py timeout 0.0ms 95.4MB 777ms 80ms pypy 3.10.16
python 8.py timeout 0.0ms 14.2MB 37ms 10ms pyston 3.8.12

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 2.ml 1159ms 5.5ms 6.1MB 1150ms 0ms ocaml 5.3.0
python 8.py timeout 0.0ms 14.5MB 47ms 10ms cpython 3.13.5
python 8.py timeout 0.0ms 95.8MB 1297ms 173ms pypy 3.10.16
python 8.py timeout 0.0ms 13.7MB 60ms 20ms pyston 3.8.12

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 2.ml 294ms 4.6ms 5.2MB 283ms 0ms ocaml 5.3.0
python 8-m.py 1962ms 22ms 93.3MB 6350ms 247ms pypy 3.10.16
python 8.py timeout 0.0ms 14.0MB 83ms 20ms cpython 3.13.5
python 8.py timeout 0.0ms 13.1MB 137ms 33ms pyston 3.8.12