OCaml VS Ruby benchmarks

Current benchmark data was generated on Tue Apr 01 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 3070ms 33ms 157.2MB 2983ms 73ms ocaml 5.3.0
ruby 1-m.rb 4767ms 126ms 811.9MB 6707ms 477ms truffleruby 24.2.0
ruby 1.rb 4863ms 1.8ms 109.4MB 4763ms 83ms ruby/yjit 3.4.2
ruby 1.rb timeout 0.0ms 70.1MB 4940ms 43ms ruby 3.4.2

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 228ms 3.7ms 19.1MB 213ms 0ms ocaml 5.3.0
ruby 1.rb 508ms 33ms 20.3MB 483ms 10ms ruby/yjit 3.4.2
ruby 1-m.rb 555ms 69ms 418.8MB 1097ms 167ms truffleruby 24.2.0
ruby 1.rb 928ms 2.7ms 19.6MB 903ms 10ms ruby 3.4.2

fannkuch-redux

Input: 11

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 2.ml 2911ms 6.9ms 4.9MB 2903ms 0ms ocaml 5.3.0

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 2.ml 248ms 4.4ms 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 348ms 0.8ms 24.8MB 337ms 0ms ocaml 5.3.0
ruby 6.rb 2077ms 33ms 23.0MB 2053ms 10ms ruby/yjit 3.4.2
ruby 6-m.rb 2154ms 27ms 419.9MB 5600ms 347ms truffleruby 24.2.0
ruby 6.rb 3878ms 66ms 22.5MB 3853ms 13ms ruby 3.4.2

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 6.ml 39ms 0.7ms 7.5MB 30ms 0ms ocaml 5.3.0
ruby 6.rb 265ms 3.1ms 15.0MB 247ms 7ms ruby/yjit 3.4.2
ruby 6.rb 439ms 2.9ms 14.5MB 420ms 3ms ruby 3.4.2
ruby 6-m.rb 812ms 40ms 382.1MB 2017ms 183ms truffleruby 24.2.0

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 2.1ms 0.2ms 5.1MB 0ms 0ms ocaml 5.3.0
ruby 1.rb 35ms 0.3ms 139.0MB 12ms 24ms truffleruby 24.2.0
ruby 1.rb 53ms 1.0ms 13.1MB 40ms 2ms ruby/yjit 3.4.2
ruby 1.rb 54ms 1.4ms 12.9MB 40ms 2ms ruby 3.4.2

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 185ms 7.5ms 6.4MB 177ms 0ms ocaml 5.3.0
ruby 1.rb 331ms 1.9ms 13.5MB 313ms 3ms ruby/yjit 3.4.2
ruby 1.rb 541ms 20ms 13.0MB 527ms 3ms ruby 3.4.2
ruby 1-m.rb 654ms 36ms 370.3MB 1150ms 157ms truffleruby 24.2.0

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 557ms 5.6ms 6.6MB 547ms 0ms ocaml 5.3.0
ruby 1.rb 876ms 8.2ms 13.5MB 857ms 7ms ruby/yjit 3.4.2
ruby 1-m.rb 1234ms 21ms 404.6MB 1727ms 163ms truffleruby 24.2.0
ruby 1.rb 1479ms 10ms 13.0MB 1457ms 10ms ruby 3.4.2

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 78ms 1.8ms 5.9MB 70ms 0ms ocaml 5.3.0
ruby 1.rb 192ms 1.5ms 13.5MB 170ms 7ms ruby/yjit 3.4.2
ruby 1.rb 292ms 3.4ms 12.9MB 277ms 0ms ruby 3.4.2
ruby 1-m.rb 512ms 30ms 361.1MB 973ms 137ms truffleruby 24.2.0

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 1191ms 6.6ms 70.2MB 1147ms 30ms ocaml 5.3.0
ocaml 2.ml 2201ms 47ms 91.8MB 2147ms 40ms ocaml 5.3.0
ruby 1-m.rb 4430ms 469ms 527.4MB 11217ms 380ms truffleruby 24.2.0
ruby 1.rb timeout 0.0ms 93.6MB 4933ms 50ms ruby 3.4.2
ruby 1.rb timeout 0.0ms 94.8MB 4940ms 50ms ruby/yjit 3.4.2

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 159ms 6.2ms 21.6MB 143ms 7ms ocaml 5.3.0
ocaml 2.ml 393ms 21ms 27.7MB 377ms 3ms ocaml 5.3.0
ruby 1-m.rb 1938ms 44ms 591.3MB 5030ms 250ms truffleruby 24.2.0
ruby 1.rb 3421ms 15ms 38.3MB 3377ms 30ms ruby/yjit 3.4.2
ruby 1.rb 4437ms 12ms 37.8MB 4397ms 27ms ruby 3.4.2

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 374ms 2.2ms 5.3MB 363ms 0ms ocaml 5.3.0
ruby 2.rb 827ms 10ms 306.8MB 1060ms 120ms truffleruby 24.2.0
ruby 2.rb timeout 0.0ms 12.9MB 4980ms 7ms ruby 3.4.2
ruby 2.rb timeout 0.0ms 13.5MB 4980ms 7ms ruby/yjit 3.4.2

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 42ms 1.5ms 5.3MB 30ms 0ms ocaml 5.3.0
ruby 2-m.rb 312ms 17ms 309.9MB 547ms 110ms truffleruby 24.2.0
ruby 2.rb 1069ms 6.2ms 13.5MB 1050ms 7ms ruby/yjit 3.4.2
ruby 2.rb 2781ms 57ms 12.9MB 2763ms 7ms ruby 3.4.2

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 1038ms 11ms 546.4MB 980ms 43ms ocaml 5.3.0
ocaml 2.ml 1914ms 25ms 19.0MB 1903ms 0ms ocaml 5.3.0
ruby 1.rb timeout 0.0ms 325.4MB 4843ms 140ms ruby 3.4.2
ruby 1.rb timeout 0.0ms 327.0MB 4850ms 137ms ruby/yjit 3.4.2
ruby 1.rb timeout 0.0ms 695.1MB 5063ms 153ms truffleruby 24.2.0

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 1.ml 210ms 2.8ms 141.2MB 187ms 10ms ocaml 5.3.0
ocaml 2.ml 468ms 2.0ms 9.1MB 460ms 0ms ocaml 5.3.0
ruby 1-m.rb 1704ms 22ms 482.3MB 2477ms 170ms truffleruby 24.2.0
ruby 1.rb 3396ms 18ms 131.8MB 3303ms 80ms ruby/yjit 3.4.2
ruby 1.rb 4463ms 12ms 131.1MB 4370ms 77ms ruby 3.4.2

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.8MB 4823ms 157ms ocaml 5.3.0

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 2.ml 557ms 6.5ms 57.1MB 520ms 20ms ocaml 5.3.0

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 2.ml 4586ms 44ms 6.4MB 4573ms 0ms ocaml 5.3.0
ruby 4.rb timeout 0.0ms 12.9MB 4987ms 0ms ruby 3.4.2
ruby 4.rb timeout 0.0ms 13.5MB 4983ms 3ms ruby/yjit 3.4.2
ruby 4.rb timeout 0.0ms 425.1MB 5170ms 247ms truffleruby 24.2.0

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 2.ml 1150ms 12ms 6.1MB 1140ms 0ms ocaml 5.3.0
ruby 4.rb 4858ms 56ms 417.3MB 5143ms 210ms truffleruby 24.2.0
ruby 4.rb timeout 0.0ms 12.9MB 4983ms 7ms ruby 3.4.2
ruby 4.rb timeout 0.0ms 13.5MB 4980ms 7ms ruby/yjit 3.4.2

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ocaml 2.ml 293ms 4.9ms 5.6MB 283ms 0ms ocaml 5.3.0
ruby 4.rb 1459ms 49ms 378.8MB 1800ms 147ms truffleruby 24.2.0
ruby 4.rb timeout 0.0ms 13.0MB 4983ms 0ms ruby 3.4.2
ruby 4.rb timeout 0.0ms 13.8MB 4980ms 3ms ruby/yjit 3.4.2