Ruby VS C++ benchmarks

Current benchmark data was generated on Wed May 25 2022, full log can be found HERE

CONTRIBUTIONS are WELCOME!

[x86_64][2 cores] Intel(R) Xeon(R) Platinum 8272CL 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
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms ruby 3.1.2
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms ruby/yjit 3.1.2
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms truffleruby 22.1.0

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 959ms 4.8ms 35.5MB 927ms 20ms ruby 3.1.2
ruby 1.rb 1007ms 63ms 292.1MB 833ms 157ms ruby/yjit 3.1.2
ruby 1-m.rb 1154ms 16ms 374.0MB 1910ms 153ms truffleruby 22.1.0

coro-prime-sieve

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 3734ms 38ms 336.8MB 3510ms 207ms ruby/yjit 3.1.2
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms ruby 3.1.2
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms truffleruby 22.1.0

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 274ms 3.5ms 42.3MB 230ms 23ms ruby 3.1.2
ruby 1.rb 439ms 2.5ms 298.8MB 270ms 150ms ruby/yjit 3.1.2
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms truffleruby 22.1.0

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 6.rb 2592ms 2.6ms 296.0MB 2430ms 143ms ruby/yjit 3.1.2
ruby 6.rb 4521ms 77ms 39.5MB 4483ms 23ms ruby 3.1.2
ruby 6.rb timeout 0.0ms 0.0MB 0ms 0ms truffleruby 22.1.0

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 6.rb 520ms 7.9ms 31.2MB 493ms 13ms ruby 3.1.2
ruby 6.rb 534ms 1.0ms 287.7MB 367ms 147ms ruby/yjit 3.1.2
ruby 6-m.rb 1815ms 39ms 324.3MB 3240ms 147ms truffleruby 22.1.0

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1.cpp 1.8ms 0.7ms 1.0MB 0ms 0ms g++ 12.1.0
cpp 1.cpp 2.8ms 0.8ms 1.0MB 0ms 0ms clang++ 11.0.0
ruby 1.rb 47ms 1.2ms 138.4MB 20ms 30ms truffleruby 22.1.0
ruby 1.rb 68ms 3.3ms 29.9MB 46ms 8ms ruby 3.1.2
ruby 1.rb 255ms 11ms 286.7MB 106ms 136ms ruby/yjit 3.1.2

json-serde

Input: sample 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 395ms 1.2ms 48.4MB 353ms 27ms ruby 3.1.2
ruby 1.rb 572ms 1.1ms 305.6MB 413ms 140ms ruby/yjit 3.1.2
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms truffleruby 22.1.0

Input: canada 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 3803ms 283ms 419.3MB 3567ms 220ms ruby/yjit 3.1.2
ruby 1.rb 3923ms 1.6ms 162.5MB 3800ms 103ms ruby 3.1.2
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms truffleruby 22.1.0

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 601ms 3.2ms 30.2MB 573ms 13ms ruby 3.1.2
ruby 1.rb 668ms 1.4ms 286.7MB 507ms 147ms ruby/yjit 3.1.2
ruby 1-m.rb 1118ms 34ms 324.3MB 1683ms 130ms truffleruby 22.1.0

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 1454ms 1.2ms 286.8MB 1283ms 153ms ruby/yjit 3.1.2
ruby 1.rb 1827ms 148ms 30.2MB 1800ms 10ms ruby 3.1.2
ruby 1-m.rb 1929ms 66ms 366.3MB 2780ms 180ms truffleruby 22.1.0

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 334ms 0.5ms 30.0MB 313ms 3ms ruby 3.1.2
ruby 1.rb 419ms 1.1ms 286.8MB 280ms 123ms ruby/yjit 3.1.2
ruby 1-m.rb 801ms 86ms 311.0MB 1277ms 97ms truffleruby 22.1.0

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms ruby 3.1.2
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms ruby/yjit 3.1.2
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms truffleruby 22.1.0

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1-m.rb 3899ms 12ms 522.4MB 7130ms 253ms truffleruby 22.1.0
ruby 1.rb 3919ms 269ms 300.9MB 3750ms 147ms ruby/yjit 3.1.2
ruby 1.rb 4824ms 19ms 44.4MB 4790ms 17ms ruby 3.1.2

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 167ms 0.4ms 0.9MB 160ms 0ms g++ 12.1.0
cpp 0-i.cpp 212ms 0.4ms 1.1MB 200ms 0ms clang++ 11.0.0
cpp 1.cpp 307ms 5.8ms 0.9MB 293ms 0ms g++ 12.1.0
cpp 1.cpp 392ms 6.8ms 1.1MB 383ms 0ms clang++ 11.0.0
ruby 2.rb 1453ms 19ms 300.6MB 1823ms 127ms truffleruby 22.1.0
ruby 2.rb timeout 0.0ms 0.0MB 0ms 0ms ruby 3.1.2
ruby 2.rb timeout 0.0ms 0.0MB 0ms 0ms ruby/yjit 3.1.2

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 21ms 1.0ms 0.9MB 10ms 0ms g++ 12.1.0
cpp 0-i.cpp 24ms 1.9ms 1.1MB 13ms 0ms clang++ 11.0.0
cpp 1.cpp 33ms 0.1ms 0.9MB 20ms 0ms g++ 12.1.0
cpp 1.cpp 42ms 0.3ms 1.1MB 30ms 0ms clang++ 11.0.0
ruby 2-m.rb 547ms 17ms 293.9MB 873ms 107ms truffleruby 22.1.0
ruby 2.rb 2300ms 157ms 286.8MB 2147ms 137ms ruby/yjit 3.1.2
ruby 2.rb 2985ms 224ms 30.0MB 2960ms 10ms ruby 3.1.2

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1.cpp 369ms 18ms 7.4MB 357ms 0ms clang++ 11.0.0
cpp 1.cpp 578ms 2.4ms 7.7MB 567ms 0ms g++ 12.1.0
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms ruby 3.1.2
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms ruby/yjit 3.1.2
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms truffleruby 22.1.0

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1.cpp 78ms 5.3ms 3.7MB 67ms 0ms clang++ 11.0.0
cpp 1.cpp 138ms 9.6ms 4.0MB 130ms 0ms g++ 12.1.0
ruby 1.rb 4255ms 11ms 450.1MB 4693ms 197ms truffleruby 22.1.0
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms ruby 3.1.2
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms ruby/yjit 3.1.2

pidigits

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms ruby 3.1.2
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms ruby/yjit 3.1.2
ruby 1.rb timeout 0.0ms 0.0MB 0ms 0ms truffleruby 22.1.0

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1-m.rb 2398ms 14ms 380.8MB 4403ms 170ms truffleruby 22.1.0
ruby 1.rb 2920ms 118ms 162.8MB 2817ms 83ms ruby 3.1.2
ruby 1.rb 3138ms 10ms 420.7MB 2910ms 213ms ruby/yjit 3.1.2

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 7-m.cpp 885ms 14ms 3.2MB 1717ms 0ms clang++ 11.0.0
cpp 8-m.cpp 885ms 14ms 3.2MB 1723ms 0ms clang++ 11.0.0
cpp 7-m.cpp 886ms 13ms 1.0MB 1707ms 0ms g++ 12.1.0
cpp 8-m.cpp 905ms 2.6ms 0.9MB 1763ms 0ms g++ 12.1.0
cpp 6-im.cpp 1804ms 22ms 3.2MB 3530ms 10ms clang++ 11.0.0
cpp 6-im.cpp 1808ms 11ms 0.9MB 3423ms 7ms g++ 12.1.0
ruby 4.rb timeout 0.0ms 0.0MB 0ms 0ms ruby 3.1.2
ruby 4.rb timeout 0.0ms 0.0MB 0ms 0ms ruby/yjit 3.1.2
ruby 4.rb timeout 0.0ms 0.0MB 0ms 0ms truffleruby 22.1.0

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 7-m.cpp 226ms 6.2ms 3.2MB 413ms 0ms clang++ 11.0.0
cpp 7-m.cpp 230ms 6.3ms 1.0MB 420ms 0ms g++ 12.1.0
cpp 8-m.cpp 232ms 6.2ms 3.1MB 433ms 0ms clang++ 11.0.0
cpp 8-m.cpp 236ms 1.3ms 1.0MB 440ms 0ms g++ 12.1.0
cpp 6-im.cpp 462ms 2.2ms 1.0MB 877ms 0ms g++ 12.1.0
cpp 6-im.cpp 470ms 2.8ms 3.2MB 897ms 0ms clang++ 11.0.0
ruby 4.rb timeout 0.0ms 0.0MB 0ms 0ms ruby 3.1.2
ruby 4.rb timeout 0.0ms 0.0MB 0ms 0ms ruby/yjit 3.1.2
ruby 4.rb timeout 0.0ms 0.0MB 0ms 0ms truffleruby 22.1.0

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 7-m.cpp 63ms 1.6ms 3.1MB 103ms 0ms clang++ 11.0.0
cpp 7-m.cpp 63ms 1.3ms 0.9MB 103ms 0ms g++ 12.1.0
cpp 8-m.cpp 65ms 1.8ms 3.2MB 110ms 0ms clang++ 11.0.0
cpp 8-m.cpp 67ms 1.8ms 1.0MB 110ms 0ms g++ 12.1.0
cpp 6-im.cpp 123ms 2.8ms 0.9MB 220ms 0ms g++ 12.1.0
cpp 6-im.cpp 127ms 3.0ms 3.1MB 223ms 0ms clang++ 11.0.0
ruby 4.rb 2702ms 3.9ms 365.9MB 3373ms 150ms truffleruby 22.1.0
ruby 4.rb timeout 0.0ms 0.0MB 0ms 0ms ruby 3.1.2
ruby 4.rb timeout 0.0ms 0.0MB 0ms 0ms ruby/yjit 3.1.2